Re: passing char * to dll
Rami schrieb:
Hi all,
I call an exported function from the main program as follows
print_in_LogFile("Specific_Message_Circular_Buffer_Index", 0);
The exported function inside the dll follows
////////////////////////////////////////////////////////////////////////////////////////////////////
_declspec(dllexport)print_in_LogFile(char * text,int g_nconnection )
===================
Several issues here:
* If you do not plan to modify "test", you should pass a const pointer. Using a
char* and passing it a string literal "Specific_Message_Circular_Buffer_Index"
only works because the C++ compiler supports this special case for compatibility
with old C code.
* In modern windows applications, using "char" as a type is basically obsolete,
except for some special cases. The world is shiftin to uinicode, so you should
either use TCHAR or WCHAR/wchar_t instead.
* The variable name prefix g_ is commonly used for global variables. A functino
argument is not global. So either the g_ does not belong here, or your naming
connention is somehow unconventional.
===================
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if (text == "Specific_Message_Circular_Buffer_Index")
==================
Are you comming from the C# or Java world?
Comparing char pointers strings with "==" does compare the strings in C/C++, it
compares the pointers. To compare the strings, you need some string comparing
functions like strcmp, stricmp or CompareString, whatever is more appropriate to
your application.
==================
{
// Do something
.....
}
problem is that the comparison with the "if" gets a FALSE value though with
a debugger I can see taht it should be TRUE.
Can someone advise please?
Norbert