Groups | Blog | Home
all groups > dotnet interop > december 2005 >

dotnet interop : Problem calling unmanaged C dll in vb.net


JimmyD
12/29/2005 8:05:48 AM
Hello,
I'm having problems calling a function in an unmanaged C dll using
VB.net. The program runs, then tries to execute the following function,
and just dies, no error message, even when I use a try/catch. I've used
the following two methods:

<DllImport("myDLL.DLL")> _
Public Shared Function GetSiteKeyAddV2(ByVal easyLicense As Integer,
ByVal addOn As Integer, ByVal userpassword As String, ByVal site_code
As String, ByVal level As Integer, ByVal options As Integer, ByVal
restriction_type As Object, ByVal num_days_or_runs As Object, ByVal
license_type As Object, ByVal copies As Integer, ByVal site_key as
string) As Integer
End Function

And

Private Declare Function GetSiteKeyAddV2 Lib "myDLL.DLL" ByVal
easyLicense As Integer, ByVal addOn As Integer, ByVal userpassword As
String, ByVal site_code As String, ByVal level As Integer, ByVal
options As Integer, ByVal restriction_type As Object, ByVal
num_days_or_runs As Object, ByVal license_type As Object, ByVal copies
As Integer, ByVal site_key as string) As Integer

Here's the C function definition:
int FUNCTYPE GetSiteKeyAddV2(int easyLicense, int addOn, char
*userpassword, char *site_code,
unsigned long level, unsigned long options,
unsigned restriction_type, unsigned num_days_or_runs,
unsigned license_type, int copies,
char *site_key);

Some things I'm concerned about are the unsigned c data types (which
I've mapped to vb.net object data types, though I don't know if this is
correct), and the fact that site_key returns a string.

Any help would be much appreciated, I'm very new to the interop stuff.

Thanks -
J
Kyle Burmark
1/3/2006 2:32:02 PM
I don't think there is a UIntegerin vb.net is there? If so try that for the
unsigned c++ params. And also try using a StringBuilder for the strings. And
allocate there space to 260. Do a combo of those things and see what happens.

[quoted text, click to view]
JimmyD
1/4/2006 8:53:47 AM
Thanks, Kyle.

There is UInt16-64 in VB.net, but I never got that far. I ended up just
creating an ActiveX DLL and interfaced with the unmanaged C DLL that
way, which worked great. But thanks for your input.

Jim

[quoted text, click to view]
AddThis Social Bookmark Button