Using resources, how to ?

Hi guys,
I am using MS Visual Studio 2005 Express ( yes, the one that u can
download for free from MS website ) and I have a "little-big" problem
with my program. First of all let me say that I created a simple
console program, with his main and few functions, and I wish that my
..exe file  can drop another .exe when launched.

The other exe is another compiled program, and I wish to handle it from
my main program as resource.
There are some topics about handling resources, but I cannot find
anything of good; I know how to use LoadResource, FindResource, etc,
but both fail since I am not able to insert the resource.

I tried in many ways, but still no results...

So do you know how to insert a file ( a .exe for example ) as resource
in my program ? I tried to insert it in the Solution Explorer, but it
doesn't work ...

Any idea ?

Regards, Alex

0
xauditt (4)
9/18/2006 2:03:31 PM
vc.mfc 33608 articles. 0 followers. Follow

9 Replies
2788 Views

Similar Articles

[PageSpeed] 37

Since MFC is not included with Express I'm guessing the MFC resources won't 
work with it either (although I haven't tried Express so I don't know for 
sure).  My guess is you can just to .NET type programming, perhaps using 
WinForms, with Express and if you want to do anything more you'll have to 
upgrade.

Tom

<xauditt@gmail.com> wrote in message 
news:1158588211.806042.131640@m73g2000cwd.googlegroups.com...
> Hi guys,
> I am using MS Visual Studio 2005 Express ( yes, the one that u can
> download for free from MS website ) and I have a "little-big" problem
> with my program. First of all let me say that I created a simple
> console program, with his main and few functions, and I wish that my
> .exe file  can drop another .exe when launched.
>
> The other exe is another compiled program, and I wish to handle it from
> my main program as resource.
> There are some topics about handling resources, but I cannot find
> anything of good; I know how to use LoadResource, FindResource, etc,
> but both fail since I am not able to insert the resource.
>
> I tried in many ways, but still no results...
>
> So do you know how to insert a file ( a .exe for example ) as resource
> in my program ? I tried to insert it in the Solution Explorer, but it
> doesn't work ...
>
> Any idea ?
>
> Regards, Alex
> 


0
tserface (3860)
9/18/2006 3:04:58 PM
> Since MFC is not included with Express I'm guessing the MFC resources won't
> work with it either (although I haven't tried Express so I don't know for
> sure).  My guess is you can just to .NET type programming, perhaps using
> WinForms, with Express and if you want to do anything more you'll have to
> upgrade.
>

I dont see  how this is about MFC related resources. If VCExpress
allows custom resources, OP should be able to add it(exe).

---
Ajay

0
ajaykalra (6842)
9/18/2006 3:15:09 PM
I guess I didn't understand OP's question.  Since they posted in the MFC 
group I thought OP was trying to work with MFC type resources.
Apoloigies.

Tom

"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message 
news:1158592509.292420.208170@k70g2000cwa.googlegroups.com...
>> Since MFC is not included with Express I'm guessing the MFC resources 
>> won't
>> work with it either (although I haven't tried Express so I don't know for
>> sure).  My guess is you can just to .NET type programming, perhaps using
>> WinForms, with Express and if you want to do anything more you'll have to
>> upgrade.
>>
>
> I dont see  how this is about MFC related resources. If VCExpress
> allows custom resources, OP should be able to add it(exe).
>
> ---
> Ajay
> 


0
tserface (3860)
9/18/2006 3:42:39 PM
Resources are so fundamental which the express edition should support.

-- 
Vipin Aravind
http://www.explorewindows.com/Blogs

"Tom Serface" <tserface@msn.com> wrote in message 
news:%23TmlUkz2GHA.1796@TK2MSFTNGP06.phx.gbl...
>I guess I didn't understand OP's question.  Since they posted in the MFC 
>group I thought OP was trying to work with MFC type resources.
> Apoloigies.
>
> Tom
>
> "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message 
> news:1158592509.292420.208170@k70g2000cwa.googlegroups.com...
>>> Since MFC is not included with Express I'm guessing the MFC resources 
>>> won't
>>> work with it either (although I haven't tried Express so I don't know 
>>> for
>>> sure).  My guess is you can just to .NET type programming, perhaps using
>>> WinForms, with Express and if you want to do anything more you'll have 
>>> to
>>> upgrade.
>>>
>>
>> I dont see  how this is about MFC related resources. If VCExpress
>> allows custom resources, OP should be able to add it(exe).
>>
>> ---
>> Ajay
>>
>
> 


0
vipin (697)
9/18/2006 3:51:44 PM
Ajay Kalra ha scritto:

> > Since MFC is not included with Express I'm guessing the MFC resources won't
> > work with it either (although I haven't tried Express so I don't know for
> > sure).  My guess is you can just to .NET type programming, perhaps using
> > WinForms, with Express and if you want to do anything more you'll have to
> > upgrade.
> >
>
> I dont see  how this is about MFC related resources. If VCExpress
> allows custom resources, OP should be able to add it(exe).
>
> ---
> Ajay


In the Solution Explorer I can see a "folder" called "resources" and it
is void by default; I can easily drag and drop any item inside there,
but FindResource fails and I cannot Load that resource. So, any idea
guys ?

0
xauditt (4)
9/18/2006 3:53:13 PM
> So do you know how to insert a file ( a .exe for example ) as resource
> in my program ? I tried to insert it in the Solution Explorer, but it
> doesn't work ...
I don't have the Express version installed, but resources are pretty 
fundamental things.

You should have an .rc file with the file you want:
  1000 MYEXE "Blabla.exe"
You compile it using rc.exe and it will result in a .res file
You should add the .res to the link step

The resource type is now "MYEXE" and the Id is 1000
Obviously, you can use your own values.

Here it is (you should improve error checking, of course):

=== DumpRes.rc ===

1000 MYRES "DumpRes.cpp"

=== BuildAll.bat ===

rc DumpRes.rc
cl DumpRes.cpp DumpRes.RES

=== DumpRes.cpp ===

#include <windows.h>
#include <tchar.h>

#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>

void SaveResToFile( LPCTSTR szFileName )
{
  HRSRC hResInfo = FindResource( NULL, MAKEINTRESOURCE(1000), _T("MYRES") );
  DWORD dwSize = SizeofResource( NULL, hResInfo );

  HGLOBAL hResData = LoadResource( NULL, hResInfo );
  if( hResData ) {
    LPVOID lpMem = LockResource( hResData );
    if( lpMem ) {
      int hFile;
      hFile = _topen( szFileName,
        _O_CREAT | _O_WRONLY | _O_TRUNC | _O_BINARY,
        _S_IREAD | _S_IWRITE );
      _write( hFile, lpMem, dwSize );
      _close( hFile );
    }
  }
}

int main( void )
{
  SaveResToFile( _T("DumpRes_Src.cpp") );
  return 0;
}

================


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/19/2006 4:58:37 AM
Mihai N. ha scritto:

> > So do you know how to insert a file ( a .exe for example ) as resource
> > in my program ? I tried to insert it in the Solution Explorer, but it
> > doesn't work ...
> I don't have the Express version installed, but resources are pretty
> fundamental things.
>
> You should have an .rc file with the file you want:
>   1000 MYEXE "Blabla.exe"
> You compile it using rc.exe and it will result in a .res file
> You should add the .res to the link step
>
> The resource type is now "MYEXE" and the Id is 1000
> Obviously, you can use your own values.
>
> Here it is (you should improve error checking, of course):
>
> === DumpRes.rc ===
>
> 1000 MYRES "DumpRes.cpp"
>
> === BuildAll.bat ===
>
> rc DumpRes.rc
> cl DumpRes.cpp DumpRes.RES
>
> === DumpRes.cpp ===
>
> #include <windows.h>
> #include <tchar.h>
>
> #include <io.h>
> #include <fcntl.h>
> #include <sys\stat.h>
>
> void SaveResToFile( LPCTSTR szFileName )
> {
>   HRSRC hResInfo = FindResource( NULL, MAKEINTRESOURCE(1000), _T("MYRES") );
>   DWORD dwSize = SizeofResource( NULL, hResInfo );
>
>   HGLOBAL hResData = LoadResource( NULL, hResInfo );
>   if( hResData ) {
>     LPVOID lpMem = LockResource( hResData );
>     if( lpMem ) {
>       int hFile;
>       hFile = _topen( szFileName,
>         _O_CREAT | _O_WRONLY | _O_TRUNC | _O_BINARY,
>         _S_IREAD | _S_IWRITE );
>       _write( hFile, lpMem, dwSize );
>       _close( hFile );
>     }
>   }
> }
>
> int main( void )
> {
>   SaveResToFile( _T("DumpRes_Src.cpp") );
>   return 0;
> }
>



Thx for your help, but I don't have a .rc file associated to my
project...
I created a blank console solution, and I do not see any .rc file in
the solution folders...
Plus  Idon't understand this line:
"SaveResToFile( _T("DumpRes_Src.cpp") );"
My resource is an exe, why are we going to save it as a .cpp ?
It must be dropped and used as an exe file ...

0
xauditt (4)
9/19/2006 7:04:28 AM
> Thx for your help, but I don't have a .rc file associated to my
> project...
Then add one :-)


> I created a blank console solution, and I do not see any .rc file in
> the solution folders...
I my post I have included everything: a cpp file, a rc file, and a bat to 
build it all. There is not even need for a solution.


> "SaveResToFile( _T("DumpRes_Src.cpp") );"
> My resource is an exe, why are we going to save it as a .cpp ?
> It must be dropped and used as an exe file ...
Because my sample rc includes a cpp file, then I save one.
If you include an exe, you can call it with the exe name as parameter.
I just wanted to give a complete, working solution, without posting a binary 
file here (the exe).


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
9/20/2006 8:25:01 AM
Mihai N. ha scritto:

> > Thx for your help, but I don't have a .rc file associated to my
> > project...
> Then add one :-)
>
>
> > I created a blank console solution, and I do not see any .rc file in
> > the solution folders...
> I my post I have included everything: a cpp file, a rc file, and a bat to
> build it all. There is not even need for a solution.
>
>
> > "SaveResToFile( _T("DumpRes_Src.cpp") );"
> > My resource is an exe, why are we going to save it as a .cpp ?
> > It must be dropped and used as an exe file ...
> Because my sample rc includes a cpp file, then I save one.
> If you include an exe, you can call it with the exe name as parameter.
> I just wanted to give a complete, working solution, without posting a binary
> file here (the exe).
>
>
> --
> Mihai Nita [Microsoft MVP, Windows - SDK]
> http://www.mihai-nita.net
> ------------------------------------------
> Replace _year_ with _ to get the real email






Mihai,
thanks for your reply, in the following 2 or 3 days I will make some
experiment with your code, I will see if it works with my IDE and if it
is what I was looking for. Please keep in touch with this post, I
really need your help and, again, thank you for your support,

best regards, alex

0
xauditt (4)
9/20/2006 8:32:17 AM
Reply:

Similar Artilces: