Wrapping a COM DLL

  • Thread starter Thread starter Sam Martin
  • Start date Start date
S

Sam Martin

hi all,

i've asked a similar question recently regarding accessing the Windows
Address Book by creating a wrapper class in C#

I need to know whether I'm barking up the wrong the tree?

What i've started doing is creating the required structs and declaring
function calls within the wab32.dll in managed code (C#) but the problem i'm
now faced with having to pass an pointer (IntPtr) to an interface as a
parameter to one of the functions.

Do i have to declare the interfaces i need as c# interfaces? or can i need
to DllImport them?

if you know what i'm talking about then you probably know i don't

any help / pointers appreciated

tia
Sam Martin
 
Sam,

Which function are you trying to declare in wab32.dll? If you can give
the function (and possibly the unmanaged declaration) it would help
tremendously.
 
hi nick,

thanks for reply,

it's
HRESULT WABOpen(
LPADRBOOK *lppAdrBook,
LPWABOBJECT *lppWABObject,
LPWAB_PARAM lpWABParam,
DWORD Reserved2
);

Basically i'm guessing the implementation would be something like

[DllImport("wab32.dll")]
static public extern uint WABOpen(ref IntPtr lppAdrBook, ref IntPtr
lppWABObject, ref IntPtr lpWABParam, uint Reserved2);

so you can obtain an IntPtr to an object (interface) that has a series of
methods, how do you then invoke those methods?

Thanks
Sam





Nicholas Paldino said:
Sam,

Which function are you trying to declare in wab32.dll? If you can give
the function (and possibly the unmanaged declaration) it would help
tremendously.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sam Martin said:
hi all,

i've asked a similar question recently regarding accessing the Windows
Address Book by creating a wrapper class in C#

I need to know whether I'm barking up the wrong the tree?

What i've started doing is creating the required structs and declaring
function calls within the wab32.dll in managed code (C#) but the problem i'm
now faced with having to pass an pointer (IntPtr) to an interface as a
parameter to one of the functions.

Do i have to declare the interfaces i need as c# interfaces? or can i need
to DllImport them?

if you know what i'm talking about then you probably know i don't

any help / pointers appreciated

tia
Sam Martin
 
Sam,

You should actually define the IAddrBook interface in your code (using
the appropriate ComImport and Guid attributes as well), and then set the
return type to that. The COM interop layer will take care of it. Just make
sure that the parameter type is "ref IAddrBook".


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sam Martin said:
hi nick,

thanks for reply,

it's
HRESULT WABOpen(
LPADRBOOK *lppAdrBook,
LPWABOBJECT *lppWABObject,
LPWAB_PARAM lpWABParam,
DWORD Reserved2
);

Basically i'm guessing the implementation would be something like

[DllImport("wab32.dll")]
static public extern uint WABOpen(ref IntPtr lppAdrBook, ref IntPtr
lppWABObject, ref IntPtr lpWABParam, uint Reserved2);

so you can obtain an IntPtr to an object (interface) that has a series of
methods, how do you then invoke those methods?

Thanks
Sam





message news:%[email protected]...
Sam,

Which function are you trying to declare in wab32.dll? If you can give
the function (and possibly the unmanaged declaration) it would help
tremendously.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sam Martin said:
hi all,

i've asked a similar question recently regarding accessing the Windows
Address Book by creating a wrapper class in C#

I need to know whether I'm barking up the wrong the tree?

What i've started doing is creating the required structs and declaring
function calls within the wab32.dll in managed code (C#) but the
problem
i'm
now faced with having to pass an pointer (IntPtr) to an interface as a
parameter to one of the functions.

Do i have to declare the interfaces i need as c# interfaces? or can i need
to DllImport them?

if you know what i'm talking about then you probably know i don't

any help / pointers appreciated

tia
Sam Martin
 
ok, so i think i've got it

basically define the IAddrBook interface in c# - how do you know what Com
attribs to use
I've been looking for a while now and still no good examples of how to do
this. (normally the interop classes are created by tlbimp no?)

thanks again mate

sam


Nicholas Paldino said:
Sam,

You should actually define the IAddrBook interface in your code (using
the appropriate ComImport and Guid attributes as well), and then set the
return type to that. The COM interop layer will take care of it. Just make
sure that the parameter type is "ref IAddrBook".


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sam Martin said:
hi nick,

thanks for reply,

it's
HRESULT WABOpen(
LPADRBOOK *lppAdrBook,
LPWABOBJECT *lppWABObject,
LPWAB_PARAM lpWABParam,
DWORD Reserved2
);

Basically i'm guessing the implementation would be something like

[DllImport("wab32.dll")]
static public extern uint WABOpen(ref IntPtr lppAdrBook, ref IntPtr
lppWABObject, ref IntPtr lpWABParam, uint Reserved2);

so you can obtain an IntPtr to an object (interface) that has a series of
methods, how do you then invoke those methods?

Thanks
Sam





message news:%[email protected]...
Sam,

Which function are you trying to declare in wab32.dll? If you can give
the function (and possibly the unmanaged declaration) it would help
tremendously.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

hi all,

i've asked a similar question recently regarding accessing the Windows
Address Book by creating a wrapper class in C#

I need to know whether I'm barking up the wrong the tree?

What i've started doing is creating the required structs and declaring
function calls within the wab32.dll in managed code (C#) but the problem
i'm
now faced with having to pass an pointer (IntPtr) to an interface as a
parameter to one of the functions.

Do i have to declare the interfaces i need as c# interfaces? or can
i
need
to DllImport them?

if you know what i'm talking about then you probably know i don't

any help / pointers appreciated

tia
Sam Martin
 
cheers nick, found an ms tutorial on ComImport

if anyone finds this thread with same problem ... look here
http://msdn.microsoft.com/library/d.../html/vcwlkCOMInteropPart1CClientTutorial.asp

now off to laboriously retype ms's wab api... sweet

sam

Sam Martin said:
ok, so i think i've got it

basically define the IAddrBook interface in c# - how do you know what Com
attribs to use
I've been looking for a while now and still no good examples of how to do
this. (normally the interop classes are created by tlbimp no?)

thanks again mate

sam


message news:[email protected]...
Sam,

You should actually define the IAddrBook interface in your code (using
the appropriate ComImport and Guid attributes as well), and then set the
return type to that. The COM interop layer will take care of it. Just make
sure that the parameter type is "ref IAddrBook".


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sam Martin said:
hi nick,

thanks for reply,

it's
HRESULT WABOpen(
LPADRBOOK *lppAdrBook,
LPWABOBJECT *lppWABObject,
LPWAB_PARAM lpWABParam,
DWORD Reserved2
);

Basically i'm guessing the implementation would be something like

[DllImport("wab32.dll")]
static public extern uint WABOpen(ref IntPtr lppAdrBook, ref IntPtr
lppWABObject, ref IntPtr lpWABParam, uint Reserved2);

so you can obtain an IntPtr to an object (interface) that has a series of
methods, how do you then invoke those methods?

Thanks
Sam





"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Sam,

Which function are you trying to declare in wab32.dll? If you can
give
the function (and possibly the unmanaged declaration) it would help
tremendously.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

hi all,

i've asked a similar question recently regarding accessing the Windows
Address Book by creating a wrapper class in C#

I need to know whether I'm barking up the wrong the tree?

What i've started doing is creating the required structs and declaring
function calls within the wab32.dll in managed code (C#) but the problem
i'm
now faced with having to pass an pointer (IntPtr) to an interface
as
can
 
Back
Top