EDN Admin
Well-known member
I dont know how to work with interfaces, described in header files. Please show me good articles with examples or tell what to do )
I really hope, that i can do it with C# (not C++). <span style="font-family:Courier New; font-size:x-small
I have:
- old DLL (c++/C);
- header files (one with methods and one with GUID);
- lib files (what for?).
!NO SOURCES!
here is some code in .h file:
<pre lang="x-cpp #ifdef __BUILD_DLL
#define BLNETPASS_EXPORT __declspec(dllexport)
#else
#define BLNETPASS_EXPORT
#endif
#include "BlNetpassUid.h"
extern "C"
{
BLNETPASS_EXPORT HRESULT WINAPI BlNetPassCreateA
(LPCSTR pHostName, const GUID *, VOID **);
BLNETPASS_EXPORT HRESULT WINAPI BlNetPassCreateW
(LPCWSTR pHostName, const GUID *, VOID **);
BLNETPASS_EXPORT HRESULT WINAPI CanBeUnload (DWORD dTimeout );
...
...
...
#ifdef UNICODE
#define BlNetPassCreate BlNetPassCreateW
#else
#define BlNetPassCreate BlNetPassCreateA
#endif
#undef INTERFACE
#define INTERFACE INetPass
DECLARE_INTERFACE_ (INetPass, IUnknown)
{
// IUnknown methods
STDMETHOD ( QueryInterface)(REFIID, VOID **) PURE;
STDMETHOD_ (ULONG, AddRef)() PURE;
STDMETHOD_ (ULONG, Release)() PURE;
// INetPass methods
STDMETHOD ( CreateNetPassEnum)(VOID **, REFIID cid,
REFIID iid) PURE;
};[/code]
and maybe another header would be useful
<pre lang="x-cpp DEFINE_GUID (CLSID_MatchBook , 0x40eb613d,0xa77c,0x40db,0xa4,0x8e,0xbc,0xc4,0x9f,0x13,0x15,0x73);
DEFINE_GUID (CLSID_BlackBox , 0xb18e7ff6,0x97db,0x463e,0x9e,0xa8,0x46,0xc8,0x0a,0xc4,0x0c,0x6a);
DEFINE_GUID (IID_INetPassEnum , 0xe74a0be4,0x7dab,0x4c8d,0x82,0xe0,0x77,0x90,0x9f,0x27,0xaa,0xed);
DEFINE_GUID (IID_INetPassDevice , 0xaf0d9f29,0xe4b1,0x415d,0xbb,0x65,0xed,0x64,0x23,0x3e,0xe7,0xe1);
...
...[/code]
what i need:
- call BlNetPassCreateA;
- get pointer to interface INetPass (he has no GUID in .h);
- run interface method CreateNetPassEnum;
- get pointer to interface INetPassEnum and so on ...
what i did:
<pre lang="x-c# ...
...
[DllImport("BlNetpassApi")]
public static extern int BlNetPassCreateA(string pHostName, ref Guid GUID, out IntPtr rINetPass);
...
...
IntPtr something;
Guid temp_guid = Guid.Empty;
int temp_int = BlNetPassCreateA(null, ref temp_guid, out something);[/code]
ok! IntPtr contains some data, but whats next ... how to describe interface that is behind and call its method? ((((((((
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article
I really hope, that i can do it with C# (not C++). <span style="font-family:Courier New; font-size:x-small
I have:
- old DLL (c++/C);
- header files (one with methods and one with GUID);
- lib files (what for?).
!NO SOURCES!
here is some code in .h file:
<pre lang="x-cpp #ifdef __BUILD_DLL
#define BLNETPASS_EXPORT __declspec(dllexport)
#else
#define BLNETPASS_EXPORT
#endif
#include "BlNetpassUid.h"
extern "C"
{
BLNETPASS_EXPORT HRESULT WINAPI BlNetPassCreateA
(LPCSTR pHostName, const GUID *, VOID **);
BLNETPASS_EXPORT HRESULT WINAPI BlNetPassCreateW
(LPCWSTR pHostName, const GUID *, VOID **);
BLNETPASS_EXPORT HRESULT WINAPI CanBeUnload (DWORD dTimeout );
...
...
...
#ifdef UNICODE
#define BlNetPassCreate BlNetPassCreateW
#else
#define BlNetPassCreate BlNetPassCreateA
#endif
#undef INTERFACE
#define INTERFACE INetPass
DECLARE_INTERFACE_ (INetPass, IUnknown)
{
// IUnknown methods
STDMETHOD ( QueryInterface)(REFIID, VOID **) PURE;
STDMETHOD_ (ULONG, AddRef)() PURE;
STDMETHOD_ (ULONG, Release)() PURE;
// INetPass methods
STDMETHOD ( CreateNetPassEnum)(VOID **, REFIID cid,
REFIID iid) PURE;
};[/code]
and maybe another header would be useful
<pre lang="x-cpp DEFINE_GUID (CLSID_MatchBook , 0x40eb613d,0xa77c,0x40db,0xa4,0x8e,0xbc,0xc4,0x9f,0x13,0x15,0x73);
DEFINE_GUID (CLSID_BlackBox , 0xb18e7ff6,0x97db,0x463e,0x9e,0xa8,0x46,0xc8,0x0a,0xc4,0x0c,0x6a);
DEFINE_GUID (IID_INetPassEnum , 0xe74a0be4,0x7dab,0x4c8d,0x82,0xe0,0x77,0x90,0x9f,0x27,0xaa,0xed);
DEFINE_GUID (IID_INetPassDevice , 0xaf0d9f29,0xe4b1,0x415d,0xbb,0x65,0xed,0x64,0x23,0x3e,0xe7,0xe1);
...
...[/code]
what i need:
- call BlNetPassCreateA;
- get pointer to interface INetPass (he has no GUID in .h);
- run interface method CreateNetPassEnum;
- get pointer to interface INetPassEnum and so on ...
what i did:
<pre lang="x-c# ...
...
[DllImport("BlNetpassApi")]
public static extern int BlNetPassCreateA(string pHostName, ref Guid GUID, out IntPtr rINetPass);
...
...
IntPtr something;
Guid temp_guid = Guid.Empty;
int temp_int = BlNetPassCreateA(null, ref temp_guid, out something);[/code]
ok! IntPtr contains some data, but whats next ... how to describe interface that is behind and call its method? ((((((((
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article