|
If you're using Unicode it can be done more efficiently than that:
std::wstring LoadString(HINSTANCE hInstance, UINT uID)
{
LPCWSTR pString;
int res = LoadStringW(hInstance, uID, (LPWSTR)(&pString), 0);
if (res == 0)
return std::wstring();
return std::wstring(pString, res);
}
MSDN on LoadString[^]:
If this parameter is 0, then lpBuffer receives a read-only pointer to the resource itself.
NOTE: Raw string resources are not NULL terminated.
Steve
|
|
|
|
|
Cool, I'd either forgotten about or never known the behaviour of LoadString when you pass zero as the buffer size.
What's the reason this wouldn't work on ANSI as well?
|
|
|
|
|
I'm not positive, but it doesn't seem to. Note that the documentation says it returns a pointer to the raw resource and string resources are always Unicode, so perhaps this is a reason. In fact, in the ANSI case 0xFFFFffff was returned to indicate an error (when 0 is passed as the buffer size), which isn't mentioned in the documentation.
Steve
|
|
|
|
|
Thanks for that, I'll stick that on the list as the first new thing I've learnt today.
Ash
|
|
|
|
|
|
Very nice and useful..Thanx
|
|
|
|
|
gmallax wrote: Very nice and useful
Then please upvote. Thanks, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
hi,
here we declare char buffer as char buffer[ 1024 ] = { '\0' }..
How to release this?
|
|
|
|
|
It is released at the next }
ReturnType SomeClass::SomeFunction(SomeParams)
{
char buffer[1024] = {0};
return ReturnType::SomeValue;
} cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi..
can u please help me to solve this error... i'm getting the following error
"fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786) "
I'm using vc6.0 and in my project settings options - there are no such options like /Og , /Oa .. but still i'm getting the error.
can anyone suggest me some solution asap..
Thanks in advance...
Archana
|
|
|
|
|
I had a few of those. I think I rearranged some of the code to get it to work. But it was a long time ago. Use #error directive at the top of your source file that fails, move it downwards and see where it breaks. Then, try rearranging your code at that point.
|
|
|
|
|
try rebuild/clean the solution once before running
|
|
|
|
|
I have a vc++ application that has been showing odd characters on Japanese Windows installations.
It shows up an japanese katakana letter O (U + 30AA) instead of the micron character µ (mu)
i am using
sprintf(Buf, "%d µV", Values[i]);
My very simple task is to embed or force the "µ" symbol to remain as-is despite language settings.
Surely there is an easy method that I am missing somewhere!? Does anyone know an answer?
Much appreciation for any help.
|
|
|
|
|
Don't use ANSI strings, use UNICODE strings, ANSI strings will use the local Codepage for character conversions wich causes your problem.
|
|
|
|
|
Hi,
What windows message will be send to the application while closing the applcation[End Process] via task manager?
Thanks,
|
|
|
|
|
If you use the "End Task" button from the "Applications" tab the WM_CLOSE message is used. If you use the "End Process" button from the "Processes" tab it's closed forcefully and receives no notification.
Steve
|
|
|
|
|
For "End Task", system sends WM_CLOSE to the app window and wait for a specified time. After the time out if the window is not closed, "Application not responding" message will be shown, and the app is closed forcefully , if you select "End Now".
|
|
|
|
|
Hi,
I have to work on a project developed in Visual C++ 6 and it need to migrate to Visual Studio 2008.
Can anyone suggest me below things:
- What things one should take care?
- Is there any procedure to do that?
Please provide me as much as information you can provide.
Thanks,
Sachin
|
|
|
|
|
Hi,
Microsoft releases a list of what they call 'Breaking Changes' each time they release a new compiler.
Breaking Changes in Visual C++ .NET 2003[^]
Breaking Changes in the Visual C++ 2005 Compiler[^]
Breaking Changes in Visual C++ 2008[^]
Breaking Changes in Visual C++ 2010[^]
When I am upgrading legacy VC6 applications... I would say that one of the most common problems that I find is within the STL. For example VC6 iterators could be compared to NULL which was non-compliant with the standards. You will now need to compare it to the container.end()
Hmmm I guess another issue I see alot is the forced conformance in for-loop scope. It seems alot of VC6 C++ software engineers would re-use variables outside of the loop scope. You can disable the conformance but I usually take the time to fix it.
Another common issue that I find within MFC projects... is that some of the MFC message handler function signatures have been changed from UINT to LRESULT.
Thats all I can really think of at the moment...
Best Wishes,
-David Delaune
|
|
|
|
|
Hello every body !
Now I add some messages in the MainFrame:
1、#define WM_MSG_UPLOAD WM_USER+101
2、afx_msg LRESULT OnUploadMsg(WPARAM wParam,LPARAM lParam);
3、ON_MESSAGE(WM_MSG_UPLOAD,OnUploadMsg)
4、At last, I pose a MessageBox in the "OnUploadMsg" function.
In the Dll:
void MainMsg()
{
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
}
But in the debug mode, AfxGetMainWnd() also is NULL. how can I send the message from the dll space to the MainFrame?
thanks for your reply !
|
|
|
|
|
Are you sure that the window is created before MainMsg() in dll is being called? If not, m_pMainWnd member of theApp will be NULL.
|
|
|
|
|
First , thanks for you reply !
Of course,I start the main program first, the m_pMainWnd is impositioned be NULL.
when the MainFrame OnCreate,I load the DLL. and when I click some menu command,it load the dll'function ,so...
I means that how to design the Inform Mechanism, like dll inform to the MainFrame ?
|
|
|
|
|
if no other way, try adding a function such as SetHwnd(HWND hWnd) in dll, to pass window handle. From dll, use this handle to call ::SendMessage(hwnd, .. ..)
|
|
|
|
|
I see, thank you very much!
|
|
|
|
|
Is your DLL an extension DLL and does it call AfxInitExtensionModule() in DLLMain (or whatever you've called it)?
It sounds like you're building a regular DLL and have created your own CWinApp derived object in the DLL. As the main window isn't created by the DLL m_pMainWindow is zero and AfxGetMainWnd hasn't got a lot to return.
Have a quick gawp at this.[^] It's got some more info about extenstion DLLs.
Cheers,
Ash
|
|
|
|