 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Grety Guest
|
Posted: Sun Mar 27, 2005 7:34 pm Post subject: FindHInstance(); |
|
|
Hi
There is a exe file which shows Hello World named : KLAK.exe
in RC file I wrote :
IDW Exe "klak.exe"
In my Form1->Button1Click I wrote :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h=FindHInstance();
HRSRC hr=FindResource(h,"IDW","Exe");
HGLOBAL hg=LoadResource(h,hr);
LPSTR lp=(LPSTR)LockResource(hg);
system("klak.exe");
FreeResource(hg);
return 0;
}
But I know its not working
first of alll what should I write in FindHInstance(); pranthesis?
The Project is about execute a exe file which is inside another exe file :-)
|
|
| Back to top |
|
 |
Ed Mulroy [TeamB] Guest
|
Posted: Mon Mar 28, 2005 12:32 am Post subject: Re: FindHInstance(); |
|
|
I have never heard of a function named FindHinstance.
If you place this at the top of the source file
extern HINSTANCE _hInstance;
The variable _hInstance is the program's instance handle, it's
HINSTANCE. The variable is created and initialized by the compiler's
startup code.
.. Ed
"Grety" <valid (AT) emailaddress (DOT) com> wrote
| Quote: | Hi
There is a exe file which shows Hello World named : KLAK.exe
in RC file I wrote :
IDW Exe "klak.exe"
In my Form1->Button1Click I wrote :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE h=FindHInstance();
HRSRC hr=FindResource(h,"IDW","Exe");
HGLOBAL hg=LoadResource(h,hr);
LPSTR lp=(LPSTR)LockResource(hg);
system("klak.exe");
FreeResource(hg);
return 0;
}
But I know its not working
first of alll what should I write in FindHInstance(); pranthesis?
The Project is about execute a exe file which is inside another exe
file
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Mar 28, 2005 6:16 am Post subject: Re: FindHInstance(); |
|
|
"Ed Mulroy [TeamB]" <dont_email_me (AT) invalid (DOT) com> wrote
| Quote: | I have never heard of a function named FindHinstance.
|
It is defined in the VCL's System unit:
Returns the instance handle of the module that contains a specified
address.
extern PACKAGE long __fastcall FindHInstance(void * Address);
| Quote: | If you place this at the top of the source file
extern HINSTANCE _hInstance;
The variable _hInstance is the program's instance handle, it's
HINSTANCE. The variable is created and initialized by the
compiler's startup code.
|
Use the global HInstance variable instead.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Mar 28, 2005 6:29 am Post subject: Re: FindHInstance(); |
|
|
"Grety" <valid (AT) emailaddress (DOT) com> wrote
| Quote: | in RC file I wrote :
IDW Exe "klak.exe"
|
Change that to the following:
IDW RCDATA "klak.exe"
| Quote: | In my Form1->Button1Click I wrote :
|
Change that to the following instead:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HMODULE hm = (HMODULE) HInstance;
HRSRC hr = FindResource(hm, "IDW", RT_RCDATA);
if( hr )
{
DWORD dwSize = SizeOfResource(hm, hr);
HGLOBAL hg = LoadResource(hm, hr);
if( hg )
{
LPVOID lp = LockResource(hg);
if( lp )
{
HANDLE hFile = CreateFile(".\klak.exe", GENERIC_WRITE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if( hFile != INVALID_HANDLE_VALUE )
{
DWORD dwWritten = 0;
WriteFile(hFile, lp, dwSize, &dwWritten, NULL);
CloseHandle(hFile);
if( dwWritten == dwSize )
WinExec(".\klak.exe", SW_SHOW);
}
}
}
}
}
Which can then be simplified to the following:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TResourceStream *RS = new TResourceStream(HInstance, "IDW",
RT_RCDATA);
try
{
TFileStream *FS = new TFileStream(".\klak.exe", fmCreate);
try {
FS->CopyFrom(RS, 0);
}
__finally {
delete FS;
}
}
__finally {
delete RS;
}
WinExec(".\klak.exe", SW_SHOW);
}
Gambit
|
|
| Back to top |
|
 |
Grety Guest
|
Posted: Wed Mar 30, 2005 8:10 pm Post subject: Re: FindHInstance(); |
|
|
Its working well thanks.
But I have to change the lines to the new one by O => o :
DWORD dwSize = SizeOfResource(hm, hr);
DWORD dwSize = SizeofResource(hm, hr);
Thanks for your help
I'm doing my project well.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|