Results 1 to 32 of 32

Thread: c/c++ code for vb6 multithreading

Hybrid View

  1. #1

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2021
    Posts
    144

    Re: c/c++ code for vb6 multithreading

    Quote Originally Posted by The trick View Post
    Do you have troubles to translate from VB6 to C++?
    Hello The Trick,

    I have gone through the link you provided.Everything is done by modMultiThreading.bas module.It is not so easy to translate the module into c/c++ since it is so advanced that you are using many undocumented apis in it.You know how much I struggled to get rtcMsgBox api work which could not have happened without your awesome support.

    I could not even understand what JSVenu suggested me for avoiding additional vb actx dll in my first post regarding undocumented APIs.

    So I request you to provide me a simple c/c++ dll like I requested FireHacker containing same functionality as modMultiThreading2.bas for which I will be happy.

    Thanks

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2021
    Posts
    144

    Re: c/c++ code for vb6 multithreading

    Quote Originally Posted by The trick View Post
    Do you have troubles to translate from VB6 to C++?
    Hello The Trick,

    I want a standard c/c++ win32 dll containing the following function exported:

    vbCreateThreadfromcdll() which is similar to vbCreateThread of modMultiThreading2.bas

    Thanks

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2021
    Posts
    144

    Re: c/c++ code for vb6 multithreading

    Hello The Trick,

    I wrote a small win32 c/c++ dll which exports a function initvbruntime() based on your modMultiThreading module as follows:




    Code:
    #include "stdafx.h"
    #include <ole2.h>
    #include "vbsim1.h"
    typedef long (__stdcall *pVBDllGetClassObject) (HINSTANCE Unknown1,long Unknown2,PVOID Unknown3_vbheader,REFCLSID, REFIID, LPVOID*);//HINSTANCE h  REFCLSID 
    typedef long (__stdcall *pGetMem4) (PVOID src,PVOID dst);//,REFCLSID, REFIID, LPVOID*);//HINSTANCE h  REFCLSID 
    pVBDllGetClassObject pv1;
    pGetMem4 pRtlMoveMemory;
    HANDLE vbHandle;
    HANDLE msvbvmvbHandle;
    IDispatch *IDisp=NULL;
    
    
    
    
    // Exported function.
    __declspec(dllexport) int initvbruntime(void)
    {
    	INT		vbDLLPointer;
    	PVOID	VBLIBPointerThunRTMain;
    	PVOID	VBLIBPointerVDGCO;
    	HANDLE	VBThread;
    	PVOID	VBLIBPointerDGCO;
        PVOID   ptr;
    	 CLSID      clsid;
    	 HRESULT	   hr,hr1;
    	ULONG lOldProtect;
    	msvbvmvbHandle=LoadLibrary("msvbvm60.dll");
    	pRtlMoveMemory=(pGetMem4)GetProcAddress((struct HINSTANCE__ *)msvbvmvbHandle, "GetMem4");
    	vbHandle = GetModuleHandle(NULL);//LoadLibrary(DLLName);	
    	//VBLIBPointerDGCO = GetProcAddress(vbHandle,"DllGetClassObject");
    	/* Load the VB DLL								*/
    	//vbDLLPointer = *(int*)((int)VBLIBPointerDGCO + 2);																/* Get the Project Pointer						*/
    	// Get e_lfanew
    	pRtlMoveMemory((int*)((int)vbHandle + 0x3C),ptr);
        //GetMem4 ByVal hModule + &H3C, ptr
        // Get AddressOfEntryPoint
    	pRtlMoveMemory(*(int*)((int)ptr) + 0x28 + vbHandle,ptr);//compilation error C2036: 'void *' : unknown size
        //GetMem4 ByVal ptr + &H28 + hModule, ptr
        // Get VBHeader
    	pRtlMoveMemory(ptr + vbHandle + 1,VBLIBPointerDGCO);//compilation error C2110: cannot add two pointers
    
    
         // Allow to write to that page
        VirtualProtect(VBLIBPointerDGCO, 0x64, PAGE_EXECUTE_READWRITE, &lOldProtect);
        
         // 'Remove Sub Main
        //ptr = mpVbHeader + &H2C
        //GetMem4 0&, ByVal ptr ' 'AddressOf mymain
        pRtlMoveMemory(VBLIBPointerDGCO + 0x2C,0);//compilation  error C2036: 'void *' : unknown size
        VirtualProtect(VBLIBPointerDGCO, 0x64, lOldProtect, 0);
    
    
    
        //GetMem4 ByVal ptr + hModule + 1, GetVBHeader
    	//msvbvmvbHandle=LoadLibrary("msvbvm60.dll");
    	VBLIBPointerThunRTMain = GetProcAddress((struct HINSTANCE__ *)msvbvmvbHandle,"ThunRTMain");								/* Get the VB Runtime Initialization Pointer	*/
        pv1=(pVBDllGetClassObject)GetProcAddress((struct HINSTANCE__ *)msvbvmvbHandle, "VBDllGetClassObject");
    
    	try
    {
    hr1=	pv1((struct HINSTANCE__ *)vbHandle,0, VBLIBPointerDGCO,clsid, IID_IDispatch, (LPVOID *)&IDisp);
    catch(...)
    {
    	if( FAILED( hr1 ) )
    {
    MessageBox(0,"\nVBDllGetClassObject failed",0,0);
    }
    }
        
    	return 42;
    }
    In the above code I used GetMem4 and VBDllGetClassObject APIs of msvbvm60.dll


    The code

    1. finds the vbheader
    2. removes sub main and
    3. the vbheader is passed as input to VBDllGetClassObject() api for initializing vb runtime.


    But I get following compilation errors when I try to build the dll which I mentioned in the above code:


    Compiling...
    vbsim1.cpp
    E:\vbsim1\vbsim1.cpp(56) : error C2036: 'void *' : unknown size
    E:\vbsim1\vbsim1.cpp(59) : error C2110: cannot add two pointers
    E:\vbsim1\vbsim1.cpp(68) : error C2036: 'void *' : unknown size
    Error executing cl.exe.

    vbsim1.dll - 3 error(s), 0 warning(s)


    Can you show how to use the GetMem4 and VBDllGetClassObject APIs of msvbvm60.dll properly without compilation errors
    and use the dll to multithread in vb6.project link is attached.

    Thanks
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2021
    Posts
    144

    Re: c/c++ code for vb6 multithreading

    Quote Originally Posted by The trick View Post
    Do you have troubles to translate from VB6 to C++?
    Hello The Trick,
    I think I am missing something in the usage of GetMemX API of msvbvm60.dll.
    Can you show me an example of how to use GetMem4 API of msvbvm60.dll in c/c++ in a proper way.

    Thanks

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