Results 1 to 32 of 32

Thread: c/c++ code for vb6 multithreading

Hybrid View

  1. #1

    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

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