Results 1 to 3 of 3

Thread: Need help converting Cpp code to vb

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    29

    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

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.
    Last edited by Merri; Jul 1st, 2008 at 03:47 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    29

    Re: Need help converting Cpp code to vb

    Thank you so much. It works!

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