Results 1 to 7 of 7

Thread: [RESOLVED] Convert C++ API to Visual Basic .NET API

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Resolved [RESOLVED] Convert C++ API to Visual Basic .NET API

    Hello here is the API written in C++:

    c++ Code:
    1. #define BMSAPI_WINDOWCAPTION "BMS Business Music System"
    2. #define WM_BMSAPI_COMMAND 0x7fff
    3.  
    4. int BMSAPISendCommand(int iBMSCommand, LPARAM ExtraData)
    5. {
    6.    HWND hwndBMS = FindWindowEx(NULL, NULL, NULL, BMSAPI_WINDOWCAPTION);
    7.    if (hwndBMS == NULL) {
    8.      // BMS not running.
    9.      // Either attempt to run BMS
    10.      // or spit out error message here...
    11.      return 0;
    12.    }
    13.    return SendMessage(hwndBMS, WM_BMSAPI_COMMAND, iBMSCommand, ExtraData);
    14. }

    I need it converted to Visual Basic .NET. I ran it through a converter but it wasn't very succesfull.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Convert C++ API to Visual Basic .NET API

    There are plenty of examples of using FindWindowEx and SendMessage around as they are two of the most common functions. A simple search of this forum should turn up plenty. I bet there's examples in the CodeBank too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Convert C++ API to Visual Basic .NET API

    vb.net Code:
    1. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
    2.     Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    3.     Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    4.  
    5.     Dim iHWND As Integer = FindWindow("BMS Business Music System", vbNullString)
    6.  
    7.     Private Function BMSAPISendCommand(ByVal iBMSCommand As Integer, ByVal ExtraData As LPARAM) As Integer
    8.         Dim hwndBMS As iHWND = FindWindowEx(NULL, NULL, NULL, BMSAPI_WINDOWCAPTION)
    9.         If hwndBMS = NULL Then
    10.             ' BMS not running.
    11.             ' Either attempt to run BMS
    12.             ' or spit out error message here...
    13.             Return 0
    14.         End If
    15.         Return SendMessage(hwndBMS, WM_BMSAPI_COMMAND, iBMSCommand, ExtraData)
    16.     End Function

    The WM_BMSAPI_COMMAND and BMSAPI_WINDOWCAPTION is not declared because i am not sure how to convert this:
    Code:
    #define BMSAPI_WINDOWCAPTION "BMS Business Music System"
    #define WM_BMSAPI_COMMAND 0x7fff
    EDIT: Okay so i think i figured out what define was, define is basicly like Dim. So here is the first define.
    Code:
     Dim BMSAPI_WINDOWCAPTION As String = "BMS Business Music System"
    I am not sure what the second one is. Is it a string? I tried integer but it ended in a syntex error.
    Also i changed line 9 to:

    Code:
    If hwndBMS = DBNull.Value Then
    Last edited by noahssite; May 25th, 2009 at 06:08 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Convert C++ API to Visual Basic .NET API

    #define basically defines a constant. '0x' is the C way to specify a hexadecimal number. That means that:
    Code:
    #define WM_BMSAPI_COMMAND 0x7fff
    would basically become:
    Code:
    Const WM_BMSAPI_COMMAND As Integer = &H7FFF
    With regards to nulls, DBNull.Value is only for null values coming from or going to a database via ADO.NET. The VB equivalent to null in C-based languages is Nothing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Convert C++ API to Visual Basic .NET API

    It is saying type iHWND and LPARAM is not defined.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Convert C++ API to Visual Basic .NET API

    For handles in VB you use IntPtr, or you can use Integer if you want. As For LPARAM, what data is being passed to that parameter? That should tell you the type. It would most likely be Integer, Long or IntPtr because an LParam is usually a number where various parts mean various things, e.g. the first two bits represent one thing and the next seven bits represent something else, etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Convert C++ API to Visual Basic .NET API

    Thank you this thread is resolved.

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