是否可以使用__declspec(dllexport),当我们不知道变量的数据类型时? [英] is it possible to use __declspec(dllexport), when data type of variable is not known to us?

查看:74
本文介绍了是否可以使用__declspec(dllexport),当我们不知道变量的数据类型时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

include <Windows.h>
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "c" {
    #endif
    __declspec(dllexport)char abc;
    __declspec(dllexport)char hello;
#ifdef __cplusplus
}
#endif

int main (void) {
    HMODULE hMod;
    int *pGlobal,i,pG;
    BOOL fFreeResult;
   
    char d[]="abc";
    char g[]="hello";
 for(i=0;i<5;i++)
 {
   hMod = GetModuleHandle (NULL);
 pGlobal = (int*)GetProcAddress (hMod, d);
        fFreeResult = FreeLibrary(hMod);
        hMod = GetModuleHandle (NULL);
 pG = (int*)GetProcAddress (hMod, g);
    printf("%u\t%u\n",pGlobal,pG);
}
    return 0;
}





此代码正常运行。但我有一个关于这一行的问题__declspec(dllexport)char abc;在这一行中,char是变量的数据类型。如果我不知道变量的数据类型那么它是可能的。如果那么?



This code is working. but i have a question about this line __declspec(dllexport)char abc; in this line char is datatype of variable. if i hvae no idea about datatype of variable then it is possblie. if then how??

推荐答案

没有。你将无法做到这一点。只知道名称,您无法知道对象的类型。这在.NET中是百分之百可能的,但在本机C ++中则不然。编译DLL时,其中没有类。你甚至不知道它是'int'还是'char *'。



如何将动态链接库(DLL)加载到Microsoft Visual C ++ 6.0项目中 [ ^ ]
No. You won't be able to do that. You cannot know the type of a object with only knowing a name. This is hundred percent possible in .NET but not in native C++. When a DLL is compiled there is no class inside it. You can't even know whether it is a 'int' or 'char *'.

How to load a dynamic link library (DLL) into a Microsoft Visual C++ 6.0 project[^]


这篇关于是否可以使用__declspec(dllexport),当我们不知道变量的数据类型时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆