CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Calling C++ DLL from VB

    I'm not sure whether this is a VB forum question or a C++ question, but I'll try here first.

    I have an API library written in C++ (including source) which compiles to several DLLs. I want to call the functions in the library from VB but I can't get the parameter passing right.

    Simple ones like:
    void yasdiMasterInitialize( char * cIniFileName, DWORD * pDriverCount)

    Can be called by:
    <DllImport("yasdimaster.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function yasdiMasterInitialize(ByVal IniFile As String, ByRef DriverCount As UInt32) As Integer
    End Function

    But anything with arrays:
    int GetDeviceName( DWORD DevHandle, char * DestBuffer, int len)

    I can't seem to get right:
    <DllImport("yasdimaster.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function GetDeviceName(ByVal DeviceNumber As UInt32, ByVal DeviceName As String, ByVal Length As Integer) As Integer
    End Function

    The above example runs but returns nothing. If I change DeviceName to ByRef, I get protected memory errors.

    The full library and documentation is available on the internet if anyone would like to download it and I've successfully compiled it with VS2010.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Calling C++ DLL from VB

    C++ has POINTERS. VB.Net doesn't, so, there is a MAJOR problem...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: Calling C++ DLL from VB

    In .net we use a string builder class as input when calling such a C function and the system automatically takes care of things. If that is not possible, is there any way of passing in a raw array from VB?
    Last edited by Zaccheus; September 2nd, 2010 at 04:54 AM.
    My hobby projects:
    www.rclsoftware.org.uk

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured