Jump to content

Check out our Community Blogs


Member Since 02 Mar 2011
Offline Last Active Dec 16 2011 12:40 AM

Topics I've Started

How do I export/import variables from a DLL to an EXE?

15 December 2011 - 09:17 PM

Honestly, this is not specifically related to Source SDK. But, I need help, and desperate... Sorry...
I am trying to export/import global variables in a Windows Env. (Visual Studio 2010 Pro Ed)
I wrote the below code, which I think is correct. However, the value is not mirrored correctly to the EXE.
Furthermore, I am using a Game Mod, where the DLLs are located in a different folder than the EXE. So, I would like someone to tell me how to correctly type in the "Additional Dependency" option.

Last, I would like to know the correct syntax of this if I would port my code to Linux.

The code:
    //DLL side
    #define __ZG_DLLEXPORT__ __declspec(dllexport)
        __ZG_DLLEXPORT__ int xyzzyx = -1;
    void smFunc()
        	if( xyzzyx < 10000 )
        		xyzzyx += 4;
        //Exe Side
    #define __ZG_DLLIMPORT__ __declspec(dllimport)
    __ZG_DLLIMPORT__ int xyzzyx;
    int XXXXX = 0; int IIII = 9;
    void funcX()
        	XXXXX = xyzzyx;
        	if( XXXXX > 100 )
        						fp = fopen("SOMETHING.txt", "a");
        				if( fp != NULL )
        					fprintf(fp, "%d", XXXXX );
        					fprintf(fp, "\n" );
/---output---/ you can ignore the Additional Dependency, because I am not familiar with the proper syntax.
    //Additional Dependency: Mod folder, which contains *.lib and *.dll files:
    //The value of xyzzyx is always -1,
    //Additional Dependency: Exe folder, the program crashes saying DLL is corrupt.

How do I export structure variables?

02 March 2011 - 11:26 PM

How do I export/import struct variables in C from a DLL to an EXE? This variable is used in both the DLL and the EXE. I do not want to use functions.

I used the following but it didnt work:
// in the DLL
__declspec(dllexport) struct exportedVar_s *exportedVar;

//in the EXE
__declspec(dllimport) struct exportedVar_s *exportedVar;

I'm using Windows, Visual Studio, C (not C++!)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download