calling a Visual C dll

D

Dave Cullen

How do I declare and call a function in a dll with VB.NET? The prototype
for my function is

extern "C" BOOL PASCAL EXPORT CreateProxCodes(char *formatpath, char
*formatname, struct CPSWorkOrder cpswo)

and the dll is called proxprog.dll, which is created with VC6

Thanks
 
D

David Browne

Dave Cullen said:
How do I declare and call a function in a dll with VB.NET? The prototype
for my function is

extern "C" BOOL PASCAL EXPORT CreateProxCodes(char *formatpath, char
*formatname, struct CPSWorkOrder cpswo)

and the dll is called proxprog.dll, which is created with VC6

Breaking this down

extern "C"

means to export the function without a C++ mangled name

BOOL

is a typedef for int. It should convert automatically to Boolean.

PASCAL

is defined as __stdcall, which is the default calling convention for
DllImport

char *

is a null terminated array of chars in the ANSI charset, which is the
default marshalling for String.

CPSWorkOrder

is a struct defined elsewhere in your VC6 header file. It must be declared
in VB as well.

EG for

struct CPSWorkOrder
{
int id;
char name[12];
};

It would be something like this


<StructLayout(LayoutKind.Sequential)> _
Structure CPSWorkOrder
Public id As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=12)> _
Public name As String
End Structure

<DllImport("proxyprog.dll")> _
Function CreateProxCodes(formatpath as string, formatname as string, cpswo
as CPSWorkOrder)
 
D

Dave Cullen

Thanks for the info. I'm getting closer...

When I try to call the exported function, VB throws an exception "Unable
to find an entry point named CreateProxCodes" in the dll. Is there
anything that'd keep a VB.NET app from seeing the function?

drc


David said:
Dave Cullen said:
How do I declare and call a function in a dll with VB.NET? The prototype
for my function is

extern "C" BOOL PASCAL EXPORT CreateProxCodes(char *formatpath, char
*formatname, struct CPSWorkOrder cpswo)

and the dll is called proxprog.dll, which is created with VC6

Breaking this down

extern "C"

means to export the function without a C++ mangled name

BOOL

is a typedef for int. It should convert automatically to Boolean.

PASCAL

is defined as __stdcall, which is the default calling convention for
DllImport

char *

is a null terminated array of chars in the ANSI charset, which is the
default marshalling for String.

CPSWorkOrder

is a struct defined elsewhere in your VC6 header file. It must be declared
in VB as well.

EG for

struct CPSWorkOrder
{
int id;
char name[12];
};

It would be something like this

<StructLayout(LayoutKind.Sequential)> _
Structure CPSWorkOrder
Public id As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=12)> _
Public name As String
End Structure

<DllImport("proxyprog.dll")> _
Function CreateProxCodes(formatpath as string, formatname as string, cpswo
as CPSWorkOrder)
 
D

David Browne

Dave Cullen said:
Thanks for the info. I'm getting closer...

When I try to call the exported function, VB throws an exception "Unable
to find an entry point named CreateProxCodes" in the dll. Is there
anything that'd keep a VB.NET app from seeing the function?

drc

Open the Visual Studio .Net 2004 Command Prompt and run

dumpbin /exports proxprog.dll

This will print a table of all of the entry points in the .dll.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top