Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

import

  • Please log in to reply
1 reply to this topic

#1 coffeenet

coffeenet

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 15 December 2011 - 09:17 PM

Hi,
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" );
        				}
        				fclose(fp);
        
        	}
    }
/---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.

Edited by coffeenet, 15 December 2011 - 10:19 PM.

  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 16 April 2012 - 05:13 AM

To add references to lib/dll in visual studio, please follow my comment in this thread -- http://forum.codecal...put-in-vc-2010/

I just tested your code on a test project: I create a project of type dynamic dll and named it ADll and put your dll code there. Then I created another project of type application and linked to the ADll following the way in that link and run it. And found that the value of that variable 'xyzzyx' is -1 in the AExe application.

Let me know if you have any confusion about it yet.
  • 0





Also tagged with one or more of these keywords: import

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