I have a WPF application which needs to invoke a function in a DLL written in C++.
ILLUSTRATION
WPFAppClass.cs (C#)
public class SampleClass
{
[DllImport("SimDll.dll")]
public static extern bool SetLoggingOn(string path);
public void Function(string path) //invoked from a click command
{
SetLoggingOn(path);
}
}
SimDll.dll (C++)
DllFnc.h
#define DECLARE_DLL __declspec(dllexport)
extern "C" {
BOOL DECLARE_DLL __stdcall SetLoggingOn(CString path);
}
FncDll.cpp (I'm aware that the header & source files are of different names)
BOOL __stdcall SetLoggingOn(CString path)
{
if (!path.IsEmpty())
{
//The issue lies here.
//I need to be able to set a boolean & a path value to be used in
//another class.
//Upon declaring GLOBAL variables & using it I get
//multiply defined symbols error.
//I tried making the variables I want STATIC, code builds, but when
//C# code invokes this method, I get MemoryAccessViolation saying
//the memory being read is protected or corrupt.
//FYI: If I do nothing & just return true or false IT WORKS
return true;
}
return false;
}
Is there a way that I can somehow set a bool & string in C++ dll from C# exe?
P.S: I'm a novice in C++ but have fair amount of C# knowledge.