🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8407

how to implement myself LoadLibrary function

#8407
From: Siney
Date: Fri, 29 Oct 2004 09:54
38 lines
1742 bytes
hi,all:

In my project, I want to pack DLL into a compressed file.I write code like 
below:


HANDLE dllfile=CreateFile("dllhack.dll",GENERIC_READ,0,0,OPEN_ALWAYS,
  FILE_ATTRIBUTE_NORMAL,0);

 HANDLE hmod=CreateFileMapping(dllfile,0,PAGE_READONLY,0,40960,"DLLFILE");
 void* ptr=MapViewOfFile(hmod,
   FILE_MAP_READ,
   0,
   0,
   0);

 funcptr func1=(funcptr)((char*)ptr+0x00001010); //0x00001010 is DLL 
function entry address
 int ret1=func1();

if DLL function is simple like:

int dllfunc()
{
    int a=10;
    int b=11;
    return a+b;
}

the code can work fine, but if call APIs like:

int dllfunc()
{
    return MessageBox(0,"Test","Test",0);
}

the code occured AV, WHY? how to implement myself LoadLibrary function that 
can work fine? thanks 
Technical Details
Message-ID: <4182135a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!news.wiretrip.org!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9ef20cab45a63808,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Siney" <siney@yeah.net>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: how to implement myself LoadLibrary function
Date: Fri, 29 Oct 2004 17:54:26 +0800
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 218.19.172.168
Message-ID: <4182135a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1099043674 218.19.172.168 (29 Oct 2004 02:54:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!news.wiretrip.org!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail