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)