How to call a function in a DLL

  • Thread starter Thread starter rowansmith
  • Start date Start date
R

rowansmith

Guest
I am writing a VB application to use the new dnsapi.lib SDK shipped in Aug 2002.

To do this I have created two projects in my solution:

1) A VB Application

2) A MFC DLL

I have used the line:

declare function CanVBSee lib "dnslib2.dll" alias "CanVBSeeThis" (byval s as string) as long.

When I try to call the function I get an Error that VB could not find the entry point for the function CanVBSeeThis in dnslib2.dll.

What is the correct way to make the DLL accessible to my VB program?

Is there a better way to make C functions available to VB? I have read about creating type libraries, but can not find a way to do this.

Thanks.

-Rowan
 
Are you using the StdCall calling convention in your DLL?

If not you may have to declare the dll import differently i.e.:
Code:
<DllImport("dnslib2.dll", EntryPoint:="CanVBSeeThis", _
    SetLastError:=False, CharSet:=CharSet.Ansi, _
    ExactSpelling:=True, _
    CallingConvention:=CallingConvention.Cdecl)> 
Public Shared function CanVBSee  (byval s as string) as long
   \\ No code goes here....
End Function

Check out the DllImport class for more info..

HTH,
Duncan
 
You dont need to create a type library for this kind of export. Try searching Google for documents on writing C DLLs to be used from VB6 (there are many) and then use the same style declare in VB.NET, doing the necessary conversions (Long becomes Integer, etc).
 
how is the function declared in the MFC DL? If you export it as a C function then it should have the correct name. When C++ functions are exported there names are mangled (technical term - not my term) to allow C++ features like overloading to work, this usually involves the addition of extra characters (such as @) in the function name.
Check with dumpbin.exe or similar what the exported function names are.
 
Back
Top