头文件
#ifndef __EXPORT_H__
#define __EXPORT_H__#if _MSC_VER > 1000
#pragma once
#endif#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport) 
#else
#define TESTDLL_API __declspec(dllimport) 
#endifextern TESTDLL_API int UserID;
extern "C" TESTDLL_API int GetShareSeg();
extern "C" TESTDLL_API void SetShareSeg(int iID);
#endif // END EXPORT.H
cpp文件:
#include "stdafx.h"
#include "export.h"#pragma data_seg("ShareData")
int UserID = 9;
#pragma data_seg()
#pragma comment(linker,"\section:ShareData,rws")int TESTDLL_API GetShareSeg()
{
UserID = UserID + 1;
return UserID;
}void TESTDLL_API SetShareSeg(int iID)
{
UserID = iID;
}大家看看有什么问题吗. dll调用文件就是调用int TESTDLL_API GetShareSeg() 这个函数几次看看能不能改变userid. 

解决方案 »

  1.   

    有呀, 
    写了一个调用程序 CString strTemp;
    int i = UserID;
    i = GetShareSeg();
    void* p = (void*)&UserID;
    p = (void*)&i;
    strTemp.Format("0X%x", p);
    strTemp.Format("%d", i);
    AfxMessageBox((LPSTR)(LPCSTR)strTemp);我是隐是调用的, 有问题吗?? 
    我运行这个程序几次(没有关闭前面的) 按理说userid应该变了呀, 为什么一直是messagebox 出来总是10呢. 
      

  2.   


    #pragma comment(linker,"\section:ShareData,rws")

    #pragma comment(linker,"/section:ShareData,rws")
    试试
      

  3.   

    ok thx 

    #pragma comment(linker,"\section:ShareData,rws")

    #pragma comment(linker,"/section:ShareData,rws")
    试试呵呵, 调了2个小时, faint. 
      

  4.   

    别怪我, 代码也是考csdn上面的, faint.