Hi,
I want to call function "asdf" from dl "x.dll":
Code:typedef int (*MYPROC)(LPVOID adr,BYTE* arg0,int arg2); HANDLE testh; LPVOID adr; MYPROC dllfunc; BYTE arg0[] = {0x01, 0x01, 0x01, 0x01, 0x00}; int arg2 = 5; int retval; testh = CreateFileA("C:\\asdf.exe",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); testh = CreateFileMappingA(testh,0,PAGE_READWRITE,0,filesize,NULL); addressx = ::MapViewOfFile(testh, FILE_MAP_WRITE,0,0,0); BYTE *arg0de = &arg0[0]; testh = LoadLibraryA("x.dll"); dllfunc = (MYPROC)GetProcAddress((HMODULE)testh,"asdf"); retval = dllfunc(adr,arg0de,arg2);
This code works perfectly fine when compiled in a Win32 console project. WHen compiled in a managed C++ form project (button click event) it throws a access violation exception when calling the function....?




Reply With Quote