|
The second comparison is the correct one.
Two facts you need to know.
1/ m_meshName is a pointer to character. Underneath, it's an integer holding an address in RAM.
2/ The compiler has seen two constant strings in your code, but only bothers to store one copy of the string "Pyramid3" in it's data segment.
So, the strcmp works as intended, and makes m_meshName point to the constant string in your code.
The 3rd comparison works by luck, as m_meshName is still pointing to that string. This is because your compiler is being efficient, it is not because your code is correct.
You are lucky.
If this doesn't sink in (it's hard until you have a lightbulb moment), I can recommend reading The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^]
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Iain Clarke wrote: If this doesn't sink in (it's hard until you have a lightbulb moment)
My lightbulb is on a dimmer switch... I think I understand what you are saying in your reply. I have just read Part 1, will follow up with Part 2 tomorrow, as it is 4.26am.
If my understanding is correct I will be making a lot of changes to my application once I figure this out.
Thank you both for your replies.
|
|
|
|
|
Hi All,
I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.
void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
{
USES_CONVERSION;
#ifdef _WINCE //for wince
LPCWSTR lpUnicodeFuncName = A2W( lpFuncName );
return(GetProcAddress(hModule, lpUnicodeFuncName));
#else // for vc6
LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
return (GetProcAddress(hModule, lpAsciiFuncName));
#endif
}
Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode.
General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter).
Also just FYI: http://blog.voidnish.com/?p=70[^]
I tried lot of ways to typecastings.. but didnot work. Please help.
Priya Sundar
|
|
|
|
|
Should the
LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
line be:
LPCSTR lpAsciiFuncName = (LPCSTR)T2A( lpFuncName );
?
That may not be the source of your trouble, but it won't help...
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
On my system this code (following Iain's suggestion), compiled with VC6 works fine both on Debug and Release build
LPCSTR lpAsciiFuncName = T2A( lpFuncName );
return (GetProcAddress(hModule, lpAsciiFuncName));
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
Still it is not working after using T2A().
And fyi I am compiling my application(vc6) in UNICODE!
Could you please show me your function call?
The below is my function call:
CString CompletePathOfDll ="E:\\sample.dll";
HINSTANCE DllHandle = LoadLibrary(CompletePathOfDll);
if (DllHandle != NULL)
{
int IsCorrectDll=(int)GetProcAddress1(DllHandle ,TEXT("Get_Data_Function"));
if(IsCorrectDll>0)
{
}
}
Thanks.
Priya Sundar
|
|
|
|
|
Hi,
I need to create new thread if I click on particular button in my MFC application.I have added following code.
AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0,
DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )
{
}
I am getting errors one of thoes error is
error C2275: 'CRuntimeClass' : illegal use of this type as an expression <br />
I have created user interface thread.Is it correct.Where I need to close thread and how to close
|
|
|
|
|
Haven't you tried CreateThread[^].
But be careful to terminate thread. For that you can see this[^].
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
I am using MFC.I think I should not use createThread.
|
|
|
|
|
You can use createThread method.There is no matter of MFC.
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
Divyang Mithaiwala wrote: You can use createThread method.There is no matter of MFC.
Actually, there is. Please read the docs[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: Actually, there is. Please read the docs[^]
Good reference
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You are correct, you should NOT be using the CreateThread()[^] Win API version if you are using MFC (Again, look at the remarks section of CWinThread class to know why).
But, if you want that kind of functionality (which you may need with UI threads), you can then create a CMyThread object and then call CMyThread::CreateThread() when you want the thread to start execution. (CMyThread is a CWinThread derivative.)
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hemlat wrote: UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )
Your method which will work as thread & belong to class then it must be define static . But is method is not belong to any class then it is no matter to have static.
hemlat wrote: AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam,
When you pass pointer/name of method use CTestcycleDlg::pfnThreadProc .
I hope this will work for your code.
Do not trust a computer...
Always check what computer is doing
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
Here is an UI thread tutorial: UI threads[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hemlat wrote: AfxBeginThread( CRuntimeClass* pfnThreadProc,LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL,UINT nStackSize = 0, DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);
What is this? Are you trying to call AfxBeginThread() , or just duplicate the prototype?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Actually I dont know how to create thread.I have tried with above code.I am seaching the code for thread creation.
|
|
|
|
|
hemlat wrote: I am seaching the code for thread creation.
Quote Selected Text
Still?! Are you kidding me?
I gave you link to an excellent UI thread tutorial yesterday. Did you read it or not? Why are you "searching" for code, BTW? You're supposed to write code if you are a programmer of any kind.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks for your reply.Just now I have started working.Morning I was busy with some other task.Just I replyed to his message he was asking me what I was doing.I started working on Link which u hv sent.
|
|
|
|
|
I need to create worker thread.Because I need to put my functionality in thread function. Can you suggest any link which will show how to create worker thread
|
|
|
|
|
Bookmark the MVP Tips[^] page. There's plenty of good essays there.
Look for "Using Worker Threads" essay for your purpose.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
thanks for your reply.I have created thread.I got article in Codeproject.Sorry for late
reply.
|
|
|
|
|
hemlat wrote: Can you suggest any link which will show how to create worker thread
Did you even bother to read the article that Rajesh provided? If you had, you would have noticied a link to this.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hemlat wrote: UINT CTestcycleDlg::pfnThreadProc(LPVOID pParam )
i think you forget to make function static
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello,
I am dealing with a problem and I would need your help.
I have two top most windows, and i want to always have one of the windows in front of the other. The solution that makes one of the windows a child of the other cannot be applied in my case.
Thank you for your help.
|
|
|
|