I am trying to load a C++ DLL in a C# program, however the variables from C++ when loaded in C# are corrupt (I think)
This is how the output should look like (this is C++)
//cout << "Loading config, please wait..." << endl;
LoadConfig();
Sleep(2000);
clear();
cout << "Your current settings are: " << endl << endl;
cout << "Resolution: " << screen_width << "x" << screen_height << endl;
cout << "Sensitivty: " << sensitivity << endl;
cout << "Smoothing: " << smoothing << endl;
cout << "FOV: " << fov << endl;
cout << "Mode: " << mode << endl;
cout << "Color: " << color << endl;
cout << "MB4: " << mb4 << endl;
cout << "MB5: " << mb5 << endl;
cout << "lClick: " << lClick << endl;
cout << "Hold : " << hold << endl;
Sleep(10000);
And this is how it actually looks like.
Resolution: 1920x1080
Sensitivty: 1
Smoothing: 1e-07
FOV: 100Your current settings are:
Mode:
1Resolution:
1920x1080Color: PURPLE
Sensitivty: 1
MB4: Smoothing: 1e-071
FOV: 100
MB5:
0
Mode: 1lClick: 0
Hold : 1Color: PURPLE
MB4: 1
MB5: 0
lClick: 0
Hold : 1
The program '[288] GynLockLoader.exe' has exited with code -1073741510 (0xc000013a).
why does this happen? the variables in C++ are correct, I am loading them thru a config loader LoadConfig();
LoadConfig() (don't mind the messy code, I don't use C++ a lot)
void LoadConfig() {
ifstream cFile("config.txt");
if (cFile.is_open())
{
string line;
while (getline(cFile, line))
{
line.erase(remove_if(line.begin(), line.end(), isspace),
line.end());
if (line.empty() || line[0] == '#')
{
continue;
}
auto delimiterPos = line.find("=");
string name = line.substr(0, delimiterPos);
string value = line.substr(delimiterPos + 1);
if (name == "resX") {
screen_width = stoi(value);
}
else if (name == "resY") {
screen_height = stoi(value);
}
else if (name == "sensitivity") {
sensitivity = stod(value);
}
else if (name == "smoothing") {
smoothing = stod(value);
}
else if (name == "fov") {
fov = stoi(value);
}
else if (name == "mode") {
mode = stoi(value);
}
else if (name == "color") {
color = value;
}
else if (name == "mb4") {
if (value == "1") {
mb4 = true;
}
else {
mb4 = false;
}
}
else if (name == "mb5") {
if (value == "1") {
mb5 = true;
}
else {
mb5 = false;
}
}
else if (name == "lClick") {
if (value == "1") {
lClick = true;
}
else {
lClick = false;
}
}
else if (name == "hold") {
if (value == "1") {
hold = true;
}
else {
hold = false;
}
}
}
}
else
{
cerr << "Couldn't open config file for reading.\n";
}
}
I call extern C in dllmain.h so I can use main()
in C# by calling DllImport
dllmain.h
extern "C"
__declspec(dllexport)
int
main(void);
And this is how I call main()
from C#
C# main();
static class Program
{
[DllImport("GynLock.dll")]
public static extern void main();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Main());
main();
}
}
Everything loads normally, I just don't understand why my output looks so weird and corrupt (?)
Can somebody help clarify this for me, maybe I am missing something basic here...