none
Need help Converting C++ Code to VB.NET RRS feed

  • Question

  • I  have the following code in C++

    #define    _MAX_FNAME        256

    typedef    struct
    {
        struct
        {
            CHAR    szFilename[ _MAX_FNAME];
            CHAR    szRevision[ 32];
        }
        upperDll;

        struct
        {
            CHAR    szFilename[ _MAX_FNAME];
            CHAR    szRevision[ 32];
        }
        lowerDll;
    }
    DLL_INFORMATION, *LPDLL_INFORMATION;

    typedef VOID ( WINAPI *CALL_BACK_FUNCTION) ( WPARAM, LPARAM);

    #ifndef    _DLL_DEVELOPMENT_
    #define    DLL_API    __declspec( dllimport)
    #else
    #define    DLL_API    __declspec( dllexport)
    #endif

    DLL_API    DWORD WINAPI    GetDllInformation( LPDLL_INFORMATION);

    How do I convert these to VB.NET equivalent so that I can call from my VB program just like the following:-

    If (GetDllInformation(dllInfo)) = 0) then
        Msgbox (dllInfo.upperDll.szFilename)

    EndIf

    Please help.



    Thank You
    • Moved by nobugzModerator Thursday, August 13, 2009 4:29 PM (From:Visual C++ Language)
    Thursday, August 13, 2009 2:52 PM

Answers

  • Well....   We need a bit more inforamtion to give you full answer, but the basic answer is p/invoke.  In VB it would look something like:
    Const MAX_FNAME As Integer = 256
    
    <StructLayout(LayoutKind.Sequential, CharSet:=Ansi)> _
    Structure DllPartInfoStruct
        <MarshalAs (UnmanagedType.ByValTStr, SizeConst:=MAX_FNAME)> _
        Public szFileName As String
        <MarshalAs (UnmanagedType.ByValTStr, SizeConst:=32)> _
         Public szRevision As String
    End Structure
    
    Structure DllInfo
      Public UpperDll As DllPartInfoStruct
      Public LowerDll As DllPartInfoStruct
    End Struct
    
    Declare Ansi Function GetDllInformation Lib "idontknowthis.dll" (ByRef dllInfo As DllInfo) As Boolean
    
    Dim info As DllInfo
    If  GetDllInfo(info) Then
       MessageBox.Show (info.UpperDll.szFileName)
    End If
    I'm assuming ansi, but maybe not, and I'm not sure what the name of the dll is that this function resides in.



    Tom Shelton
    • Proposed as answer by Waleed El-Badry Friday, August 14, 2009 7:48 AM
    • Marked as answer by KRGuy Saturday, August 15, 2009 5:06 AM
    Thursday, August 13, 2009 9:49 PM