EDN Admin
Well-known member
Hi All,
I have a solution that contains below projects:
a. DLL1 (Configuration Type : Dynamic Library (.dll))<br/>
Debug Configuration:
Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug (/MTd)
Following is the code, exported functions:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; extern <span style="color:#A31515; "C" __declspec(<span style="color:Blue; dllexport) <span style="color:Blue; void GiveMeStringByReference(<span style="color:Blue; const std::string& strName) ;
<span style="color:Blue; extern <span style="color:#A31515; "C" __declspec(<span style="color:Blue; dllexport) <span style="color:Blue; void GiveMeStringByValue(<span style="color:Blue; const std::string strName) ;
<span style="color:Blue; void GiveMeStringByReference(<span style="color:Blue; const std::string& strName)
{
<span style="color:Green; //Hey, I should not get crashed just after function execution!
}
<span style="color:Blue; void GiveMeStringByValue(<span style="color:Blue; const std::string strName)
{
<span style="color:Green; //I should get crashed just after function execution!
}
[/code]
b. TestSTL_VS2005 (Configuration Type : Application (.exe))
Debug Configuration:
Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug (/MTd)
<div style="color:Black;background-color:White; <pre>
HMODULE hDLL = LoadLibrary(_T(<span style="color:#A31515; "DLL1.dll")) ;
<span style="color:Blue; if (NULL != hDLL)
{
<span style="color:Blue; typedef <span style="color:Blue; void (*PFNGIVEMESTRINGBYREFERENCE)(<span style="color:Blue; const std::string&) ;
PFNGIVEMESTRINGBYREFERENCE pfnGiveMeStringByReference = NULL ;
pfnGiveMeStringByReference = (PFNGIVEMESTRINGBYREFERENCE) GetProcAddress(hDLL, <span style="color:#A31515; "GiveMeStringByReference") ;
pfnGiveMeStringByReference(<span style="color:#A31515; "") ;
<span style="color:Blue; typedef <span style="color:Blue; void (*PFNGIVEMESTRINGBYVALUE)(<span style="color:Blue; const std::string) ;
PFNGIVEMESTRINGBYVALUE pfnGiveMeStringByValue = NULL ;
pfnGiveMeStringByValue = (PFNGIVEMESTRINGBYVALUE) GetProcAddress(hDLL, <span style="color:#A31515; "GiveMeStringByValue") ;
pfnGiveMeStringByValue(<span style="color:#A31515; "") ;
FreeLibrary(hDLL) ;
hDLL = NULL ;
}
[/code]
1. pfnGiveMeStringByReference call works fine in VS 2005 and VS 2010 in Debug and Release modes.
2. But pfnGiveMeStringByValue call works as described below:
a. Visual Studio 2005 - Both Debug and Release works fine.
b. Visual Studio 2010 - Debug crashes.
c. Visual Studio 2010 - Release works fine.
What could be the reason that in VS 2010 SP 1 case 2.b is failing?
Details:
a. VS 2005 - Version 8.0.50727.867 (vsvista.050727-8600), Microsoft .Net Framework (Version 2.0.50727 SP2)
b. VS 2010 - Version 10.0.40219.1 SP1Rel, Microsoft .Net Framework (Version 4.0.30319 SP1Rel)
Regards,
Dhaval
View the full article
I have a solution that contains below projects:
a. DLL1 (Configuration Type : Dynamic Library (.dll))<br/>
Debug Configuration:
Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug (/MTd)
Following is the code, exported functions:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; extern <span style="color:#A31515; "C" __declspec(<span style="color:Blue; dllexport) <span style="color:Blue; void GiveMeStringByReference(<span style="color:Blue; const std::string& strName) ;
<span style="color:Blue; extern <span style="color:#A31515; "C" __declspec(<span style="color:Blue; dllexport) <span style="color:Blue; void GiveMeStringByValue(<span style="color:Blue; const std::string strName) ;
<span style="color:Blue; void GiveMeStringByReference(<span style="color:Blue; const std::string& strName)
{
<span style="color:Green; //Hey, I should not get crashed just after function execution!
}
<span style="color:Blue; void GiveMeStringByValue(<span style="color:Blue; const std::string strName)
{
<span style="color:Green; //I should get crashed just after function execution!
}
[/code]
b. TestSTL_VS2005 (Configuration Type : Application (.exe))
Debug Configuration:
Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug (/MTd)
<div style="color:Black;background-color:White; <pre>
HMODULE hDLL = LoadLibrary(_T(<span style="color:#A31515; "DLL1.dll")) ;
<span style="color:Blue; if (NULL != hDLL)
{
<span style="color:Blue; typedef <span style="color:Blue; void (*PFNGIVEMESTRINGBYREFERENCE)(<span style="color:Blue; const std::string&) ;
PFNGIVEMESTRINGBYREFERENCE pfnGiveMeStringByReference = NULL ;
pfnGiveMeStringByReference = (PFNGIVEMESTRINGBYREFERENCE) GetProcAddress(hDLL, <span style="color:#A31515; "GiveMeStringByReference") ;
pfnGiveMeStringByReference(<span style="color:#A31515; "") ;
<span style="color:Blue; typedef <span style="color:Blue; void (*PFNGIVEMESTRINGBYVALUE)(<span style="color:Blue; const std::string) ;
PFNGIVEMESTRINGBYVALUE pfnGiveMeStringByValue = NULL ;
pfnGiveMeStringByValue = (PFNGIVEMESTRINGBYVALUE) GetProcAddress(hDLL, <span style="color:#A31515; "GiveMeStringByValue") ;
pfnGiveMeStringByValue(<span style="color:#A31515; "") ;
FreeLibrary(hDLL) ;
hDLL = NULL ;
}
[/code]
1. pfnGiveMeStringByReference call works fine in VS 2005 and VS 2010 in Debug and Release modes.
2. But pfnGiveMeStringByValue call works as described below:
a. Visual Studio 2005 - Both Debug and Release works fine.
b. Visual Studio 2010 - Debug crashes.
c. Visual Studio 2010 - Release works fine.
What could be the reason that in VS 2010 SP 1 case 2.b is failing?
Details:
a. VS 2005 - Version 8.0.50727.867 (vsvista.050727-8600), Microsoft .Net Framework (Version 2.0.50727 SP2)
b. VS 2010 - Version 10.0.40219.1 SP1Rel, Microsoft .Net Framework (Version 4.0.30319 SP1Rel)
Regards,
Dhaval
View the full article