|
Sure.
Let's assume you have added a textfile to your resource with ID=IDR_TEXTFILE, and your custom resource type has the name "TEXTFILE".
You can extract the resource with the following code:
#include "stdafx.h"
#include "resource.h"
#include <TCHAR.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HRSRC hRsrc = ::FindResource( hInstance,
MAKEINTRESOURCE( IDR_TEXTFILE ),
_T("TEXTFILE") );
if ( NULL != hRsrc )
{
HGLOBAL hGlob = ::LoadResource( NULL, hRsrc );
if ( NULL != hGlob )
{
DWORD dwSize = ::SizeofResource( NULL, hRsrc );
LPVOID lpVoid = ::LockResource( hGlob );
if ( NULL != lpVoid )
{
LPCTSTR lpszString = reinterpret_cast< LPCTSTR>( lpVoid );
MessageBox( NULL, lpszString, _T("From resource"), MB_OK );
}
}
};
return 0;
}
That's it
Jens
|
|
|
|
|
|
Hmmm, one annotation:
The more I think about it the more I get convinced, that it is not allowed to just cast the memory pointer to an LPCTSTR, because the trailing zero is missing.
Instead it should be copied to an according buffer.
So it should be:
LPCTSTR lpszString = reinterpret_cast< LPCTSTR>( lpVoid );
TCHAR *tcBuffer = new TCHAR[ dwSize + 1 ];
if ( NULL != tcBuffer )
{
ZeroMemory( tcBuffer, ( dwSize + 1 ) * sizeof( TCHAR ) );
memcpy( tcBuffer, lpszString, dwSize * sizeof( TCHAR ) );
}
But this is only the case with strings.
Byte buffer or similar can't be used directly anyway (like LPCTSTR).
Jens
|
|
|
|
|
Hi all,
I want to set the screensaver timeout and screensaver..I can set the screensaver in registry..whereby it changes the screensaver in properties of desktop..but if i change the screensaver timeout in registry it doesnt change in the properties of desktop..until i restart or logoff or shutdown and restart the machine...then the change is reflected..even it doesnt even seem to realize that new value is there in registry..it always takes the value from destop properties..can anyone help..and show me some pointers or ideas on it...any help is highly appreciated..Thanks a lot in advance..
Himanshu
|
|
|
|
|
Use SystemParametersInfo, passing:
SPI_SETSCREENSAVEACTIVE to set whether the screensaver is enabled
SPI_SETSCREENSAVETIMEOUT to set the timeout.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
hi,
Thanks for the reply..but it does set the screensaver timeout and it is the same as in destop properties..but there is a flaw there..when i set thru systemparametersinfo...it starts running screensaver the same moment it passes thru the statement..I dont want that..I want only the screensaver to be set...not run the screensaver the same time..can u help..
Himanshu
|
|
|
|
|
Hi everybody,
How can I use a CString variable in regular DLL .
The compiller say "error C2501: 'CString' : missing storage-class or type specifiers" on my CString variable.
If I include < afxwin.h > to my StdAfx.h then linker say:
"nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in XXX.obj
nafxcwd.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in XXX.obj; second definition ignored"
Best regards,
Eugene Pustovoyt
|
|
|
|
|
My first guess would be to move afxwin.h out of stdafx.h.
If that doesn't work try to add this linker switch /NOD nafxcwd.lib. If that doesn't work either, then I am out of guesses.
Actually, I just had another question, are you linking dynamically to MFC or statically?
If you are linking dynamically you need to add
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Move afxwin.h had no effect?
And add this linker switch/NOD nafxcwd.lib has resulted in awful consequences (about 1500 errors )
I use a static library.
|
|
|
|
|
I was doing some reading on your linker error because I had the same problem once and the only thing that I remembered was doing that /NOD trick. Well, there was more to it that I didn't remember. Sorry about that.
I hope this works now (I got it from MSDN):
There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that's causing the problem and correct it.
Solution One - Force Linker to Link Libraries in Correct Order
Open the Project Settings dialog box by clicking Settings on the Build menu.
in the Settings For view, select (highlight) the project configuration that's getting the link errors.
Click the Link tab.
Select INPUT in the Category combo box.
In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib)
NOTE: The linker command line equivalent in /NOD:<library name="">
In the Object/library Modules edit box, insert the library names. You must ensure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib).
Solution Two - Find the Problem Module and Correct It
Perform the following steps to see the current library link order:
Open the Project Settings dialog box by clicking Settings on the Build menu.
In the Settings For view, Select (highlight) the project configuration that's getting the link errors .
Click the Link tab.
Type the following in the Project Options dialog box:
/verbose:lib
Rebuild your project. The libraries will now be listed in the output window during the linking process.
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
I know this can't be that hard, but I can seem to find it anywhere?
I know how to transfer CStrings between dialogs, but I can't figure out how to transfer double variables between dialogs.
I wish I could type better ...
|
|
|
|
|
And in what a difference?
If you transfer CString through the pointer then double is transfer through the pointer too.
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Why don't you keep a public function in the dialog class which will set the value of the double and call that function from the first dialog?
Regards,
Melwyn
|
|
|
|
|
Do you need to transfer the value or the variable?
if you want to transfer the value, a simple solution can be:
<br />
double GetYourDoubleVar() {return m_dYourdoubleVar;}<br />
if you want to transfer the variable and that only one dialog can use is do:
<br />
BOOL GetYourDoubleVar(double* d)<br />
{<br />
if(m_pdYourDouble == NULL)<br />
return FALSE;<br />
d = m_pdYourDouble;<br />
m_pdYourDouble = NULL;
return TRUE;<br />
}<br />
hope this helps
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Thank you. I will give this a try.
I wish I could type better ...
|
|
|
|
|
I just wanted to let anyone know that I found the answer to my problem. I was making it much harder than it need to be.
CMyDialogNumber2 Dlg;<br />
<br />
if( Dlg.DoModal() )<br />
{<br />
UpdateData();<br />
m_CurrentWindowValue = Dlg.m_PopUpWindowValue;
}<br />
Just thought I should follw up.
Thanks to everyone who replied.
I wish I could type better ...
|
|
|
|
|
Dear all
I will like to output % as a text to a Text File.
CString cc="Ec%0B";
message.Format(cc);
m_File.WriteString(message);
but, The file just show Ec, not Ec%0B. can someone tell me why?
Thanks
|
|
|
|
|
To output a % you need to put a \ before it.
CString cc="Ec\%0B";
message.Format(cc);
m_File.WriteString(message);
[EDIT]
Why are you using the Format statement anyways? It is not necissary in your code.
CString cc="Ec%0B";
m_File.WriteString(cc);
[/EDIT]
John
|
|
|
|
|
John M. Drescher wrote:
To output a % you need to put a \ before it.
Or use %%, as per the <codeprintf()< code=""> docs
I agree with not needing to use <code>Format(), although this may not actually be the code in his program...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
Or use %%, as per the docs
I guess its time to get some sleep.. I am soo tired...
John
|
|
|
|
|
Yeah, that's probably a good idea sometime
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi all,
I want to connect to ftp server and move file1 to a archive folder. I have been using Wininet lib. for my ftp connect and get commands, however, how do I move a file on the server to a certain directory ?
Maybe I have to use another lib. , any help is appreciated ?
Thanks.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
FTP doesn't support moving files around on the server. To do this, you'll need to download the file (GET), delete the file (DELE), change to the new directory (CD) and upload the file again (PUT). You might want to delete the file after uploading the new file, just in case you lose the connection before it uploads properly. It's very slow, but the only way you can do it using ftp.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
My, didn't I find that out early! Whenever I rename a file on an FTP server, I always ask myself, "Why didn't the protocol designers have the sense to make a rename command???".
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Yeah, it's crazy isn't it. If I ever find that I have to do something like this, I try to use telnet instead (if the server supports it), but it's a bit complex
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|