Need help converting Cpp code to vb
Code:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LRESULT copyDataResult;
HWND pOtherWnd = FindWindow(NULL, "WinLirc");
if (pOtherWnd)
{
COPYDATASTRUCT cpd;
cpd.dwData = 0;
cpd.cbData = strlen(lpCmdLine);
cpd.lpData = (void*)lpCmdLine;
copyDataResult = SendMessage(pOtherWnd,WM_COPYDATA,(WPARAM)hInstance,(LPARAM)&cpd);
// copyDataResult has value returned by other app
}
else
{
return 1;
}
return 0;
}
The code above is a command line application and I want to do code something similiar but in vb.
So far I managed to get findwindow to work in vb but is having trouble with the sendmessage() API.
How do I convert "(WPARAM)hInstance" and "(LPARAM)&cpd)" to vb6?
I just want it to do a sendmessage() function when I click on a cmd btn
Re: Need help converting Cpp code to vb
Code:
Private Const WM_COPYDATA = &H4A
Private Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As String
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Code:
Dim lngDataResult As Long, lngOtherWnd as Long, CDS As COPYDATASTRUCT
lngOtherWnd = FindWindow(vbNullString, "WinLirc")
If lngOtherWnd Then
With CDS
.dwData = 0
.lpData = Space$(32)
.cbData = Len(.lpData)
End
lngDataResult = SendMessage(lngOtherWnd, WM_COPYDATA, lngInstance, CDS)
End If
I don't know what would be the values for lpCmdLine and hInstance.
Re: Need help converting Cpp code to vb
Thank you so much. It works!