Is there a straight way to compare variables from 2 different C programs in Visual Studio? The only way of variable comparison I can come up with is writing them to the disk using file handling and then comparing them using a third program. Does Visual Studio allow variables to be saved like in MATLAB?

Edited 6 Years Ago by lotrgandalf: n/a

This is not my code...I picked it up from the internet some time ago, I wish I could give credit but I forget where I got it from..Also its in C++ but can easily be converted to C.

dllcpp.cpp

#include <windows.h>

#pragma comment(linker,"/SECTION:.shared,RWS")

#pragma data_seg(".shared")
    int x = 0;
#pragma data_seg()

extern "C" __declspec(dllexport) int getx();
extern "C" __declspec(dllexport) void setx(int val);
BOOL APIENTRY DllMain(HANDLE hmodule, DWORD dwreason, LPVOID lpreserved)
{
	switch (dwreason)
	{
		case DLL_PROCESS_ATTACH: break;
		case DLL_PROCESS_DETACH: break;
		case DLL_THREAD_ATTACH: break;
		case DLL_THREAD_DETACH: break;
	}
	return TRUE;
}

int getx()
{
	return x;
}

void setx(int val)
{
	x = val;
}

dllapp.cpp

#include <iostream>
#include <windows.h>

typedef int (*importgetx)();
typedef void (*importsetx)(int);

int main(int argc, char**argv)
{
	importgetx GetX;
	importsetx SetX;
	int choice = 0, val = 0;

	HINSTANCE hinstlib = LoadLibrary("C:\\ggcpp\\publicdll\\Debug\\dllcpp.dll");

	if (hinstlib == 0)
	{
		std::cout<<"could not load DLL!\n";
		return 1;
	}
	else
	{
		std::cout<<hinstlib<<"\n";
	}

	GetX = (importgetx)GetProcAddress(hinstlib, "getx");

	if (GetX == 0)
	{
		std::cout<<"could not load DLL function!\n";
		return 1;
	}
	else
	{
		std::cout<<GetX<<"\n";
	}

	SetX = (importsetx)GetProcAddress(hinstlib, "setx");

	if (SetX == 0)
	{
		std::cout<<"could not load DLL function!\n";
		return 1;
	}
	else
	{
		std::cout<<SetX<<"\n";
	}

	for (;;)
	{
		std::cout<<"(0)exit (1)set DLL data (2)view DLL data->";
		std::cin>>choice;
		std::cout<<"\n";

		if (choice == 0) break;

		if (choice == 1)
		{
			std::cout<<"enter new DLL value->";
			std::cin>>val;
			std::cout<<"\n";
			SetX(val);
			std::cout<<GetX()<<"\n";
		}

		if (choice == 2)
		{
			std::cout<<GetX()<<"\n";
		}
	}

	FreeLibrary(hinstlib);
	return 0;
}

Edited 6 Years Ago by gerard4143: n/a

This article has been dead for over six months. Start a new discussion instead.