MASM:访问从汇编全局C变量 [英] MASM: Accessing to global C variable from assembly

查看:273
本文介绍了MASM:访问从汇编全局C变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个程序转换图像和比较处理数据的速度,在C和汇编。我有3个项目:

I'm writing a program to convert image and compare the speed of processing data in C and assembly. I have 3 projects:


  • 在C主程序项目

  • 在C DLL转换图像

  • 在ASM DLL转换图像

在C DLL的头,我只是写道:

In C DLL header, I simply wrote:

#ifdef PROJEKTC_EXPORTS
    #define PROJEKTC_API __declspec(dllexport)
#else
    #define PROJEKTC_API __declspec(dllimport)
#endif

...

extern PROJEKTC_API unsigned int ThreadID;      

PROJEKTC_API void __cdecl funkcjaC(void* Args); 

和包括这个头后,我可以在这两个项目的主体和C DLL访问变量的ThreadID。

and after including this header, I can access variable ThreadID both in main project and C DLL.

问题时,我尝试做相同的ASM启动。我试着像的extern ASMThreadID结构:DWORD 在code座,但它不会工作。

The problem starts when I try to do the same in ASM. I tried constructions like extern ASMThreadID:dword in .code block, but it won't work.

我得到的错误:错误LNK2019:​​无法解析的外部符号功能_MyProc1 _ASMThreadID引用

我有一种感觉,它是1-2线code的问题,但我想不出我应该使用的指令。

I have a feeling that it's a matter of 1-2 lines of code, but I can't figure out which instruction should I use.

我通过链接模块定义文件的项目,ASM和添加ASM.lib文件到连接器 - 主体工程>输入。

I link the projects by module definition file in ASM and adding ASM.lib file into the Linker->Input of main project.

你有什么建议吗?

推荐答案

从旧帖子在asmcommunity.net小的帮助,我设法得到它的工作:

With small help from old posts in asmcommunity.net, I managed to get it working:


  • 在.ASM文件,。数据段前:

EXTERNDEFÇASMThreadID:DWORD


  • 在。数据段:

ASMThreadID DD 0


  • 在ASM DLL的DEF文件:

库nameOfProject
EXPORTS
...
ASMThreadID


  • 在主要的C程序头(如全局声明):

的extern __declspec(dllimport的)无符号整型ASMThreadID;

现在它的工作原理就像一个魅力。

Now it works like a charm.

在'公共'声明送我去搜索的正确方法。感谢您的帮助,伙计!

The 'public' declaration sent me to the right way of searching. Thanks for your help, mate!

这篇关于MASM:访问从汇编全局C变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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