|
It sounds like you read the variable halfway through being changed. So, the variable is not a trivial type (ie, BOOL).
Look at CCriticalSection, it's probably what you need. There's a million and one way to do this though. You could wrap the variable in a class including the CCriticalSection, and write get / set routines that use the critsect.
It really depends on the fine details.
If you have loads of static variables, it makes me suspect your initial design though. May be worth a second look. Does PlaceA need to know details of PlaceB?
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 you have loads of static variables, it makes me suspect your initial design though. May be worth a second look. Does PlaceA need to know details of PlaceB?
Yes PlaceA need to know the details of PlaceB. Can you please suggest me a quick way to overcome this problem.
|
|
|
|
|
bhanu_8509 wrote: Can you please suggest me a quick way to overcome this problem.
No, only the slow way of proper design, and wrapping access to complex variables in critical sections.
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: No, only the slow way of proper design, and wrapping access to complex variables in critical sections.
Well said, Euclid, with his "there is no royal road to geometry" is a newbie.
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]
|
|
|
|
|
bhanu_8509 wrote: I have a project with so many static variables accessed from one class to another class. I access these static variables by threads.
That's your problem. Is it possible in your case to send messages between threads, rather than accessing static variables directly?
|
|
|
|
|
If the variables are not volatile, you're already in trouble. The ideal way would be to synchronize access to the variable using thread synchronization techniques (a critical section would do, as all your threads belong to the same process).
I see you have a lot of things to read up.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hello All,
Can some one please tell me how to access the settings in gpedit.msc using VC++?
I need to set/reset various options from the gpedit.msc.
Thanks in advance.
|
|
|
|
|
I think all these options are under "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy"
|
|
|
|
|
Hello,
I am trying some Interop in my application. This is the first time I have had to pass arguments with function calls. I am experiencing some odd results.
RenderEngine.LoadNewMesh("BasicMesh", "Pyramid3", 1);
void RenderEngine::LoadNewMesh(String^ meshType, String^ meshName, int nSubsets)
{
char* cMeshType = (char*)(void*)Marshal::StringToHGlobalAnsi(meshType);
char* cMeshName = (char*)(void*)Marshal::StringToHGlobalAnsi(meshName);
m_engineRoot->LoadMesh.LoadNewMesh(cMeshType, cMeshName, nSubsets);
}
void MeshLoader::LoadNewMesh(char* meshType, char* meshName, UINT nSubsets)
{
m_meshType = meshType;
m_meshName = meshName;
m_nSubsets = 0;
m_nTotalSubsets = nSubsets;
m_pMesh = new BasicMesh();
MessageBox(0, meshName, 0, 0);
if (meshName == "Pyramid3")
MessageBox(0, (char*)"meshName is Pyramid3", 0, 0);
if (strcmp(meshName,"Pyramid3") == 0)
m_meshName = "Pyramid3";
}
MeshManager::CreateMesh(m_pMesh, m_meshName);
MeshManager::GetMeshByName("Pyramid3");
|
|
|
|
|
Mikey_H wrote: if (meshName == "Pyramid3")
the value of meshName is the address of the first character of the string. it is not a string itself. in other words, meshName is a pointer, not a string.
|
|
|
|
|
The third condition here will result true, as does the second
if (meshName == "Pyramid3")
MessageBox(0, (char*)"meshName is Pyramid3", 0, 0);
if (strcmp(meshName,"Pyramid3") == 0)
m_meshName = "Pyramid3";
if (m_meshName == "Pyramid3")
MessageBox(0, (char*)"m_meshName is Pyramid3", 0, 0);
modified on Tuesday, April 14, 2009 12:35 PM
|
|
|
|
|
right, because you've assigned meshName to m_meshName, and i assume m_meshName is a string object of some kind, one with an overloaded "==" operator which knows how to compare a C-style (char*) string to its contents. (CString or std::string?)
the problem with the first remains: you cannot compare a pointer to a static string. that's not how C-style strings work. and that's why strcmp exists.
modified on Tuesday, April 14, 2009 11:39 AM
|
|
|
|
|
|
ah. you're right. i missed that comment.
|
|
|
|
|
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
|
|
|
|