[RESOLVED] Convert C++ API to Visual Basic .NET API
Hello here is the API written in C++:
c++ Code:
#define BMSAPI_WINDOWCAPTION "BMS Business Music System"
#define WM_BMSAPI_COMMAND 0x7fff
int BMSAPISendCommand(int iBMSCommand, LPARAM ExtraData)
{
HWND hwndBMS = FindWindowEx(NULL, NULL, NULL, BMSAPI_WINDOWCAPTION);
if (hwndBMS == NULL) {
// BMS not running.
// Either attempt to run BMS
// or spit out error message here...
return 0;
}
return SendMessage(hwndBMS, WM_BMSAPI_COMMAND, iBMSCommand, ExtraData);
}
I need it converted to Visual Basic .NET. I ran it through a converter but it wasn't very succesfull.
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.
Re: Convert C++ API to Visual Basic .NET API
vb.net Code:
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
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
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
Dim iHWND As Integer = FindWindow("BMS Business Music System", vbNullString)
Private Function BMSAPISendCommand(ByVal iBMSCommand As Integer, ByVal ExtraData As LPARAM) As Integer
Dim hwndBMS As iHWND = FindWindowEx(NULL, NULL, NULL, BMSAPI_WINDOWCAPTION)
If hwndBMS = NULL Then
' BMS not running.
' Either attempt to run BMS
' or spit out error message here...
Return 0
End If
Return SendMessage(hwndBMS, WM_BMSAPI_COMMAND, iBMSCommand, ExtraData)
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
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.
Re: Convert C++ API to Visual Basic .NET API
It is saying type iHWND and LPARAM is not defined.
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.
Re: Convert C++ API to Visual Basic .NET API
Thank you this thread is resolved.