导出函数和变量,请帮助创建模板(重新访问) [英] Exporting functions and variables, plz help making a template (revisited)

查看:175
本文介绍了导出函数和变量,请帮助创建模板(重新访问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经编写了用于将函数从DLL导出到EXE的示例代码.运作良好.而且,我决定将其发布在这里以供参考.

但是,我想做一个完整的参考.因此,我需要将导出功能从EXE添加到DLL,但我无法正确实现.

我需要您的帮助来纠正我的错误.它可以正确编译,但是不断崩溃.我不确定是从导出的变量还是从导出的函数.

我会先写一些需要帮助的部分!

p.s.我讨厌这个自动标记器!!!!
*环境:Windows,语言:C


-------将功能从EXE导出到DLL. (我在这儿做错什么了?因为我的Cuz似乎没有用!!)
这段代码在EXE的头文件中.

Hi,
I have written a sample code for exporting functions from a DLL to an EXE. It worked well. And, I decided to post it here for reference.

However, I would like to make this a complete reference. So, I will need to add exporting function from an EXE to a DLL, which I failed to implement correctly.

I need your help in fixing my error. It compiles correctly, however keeps crashing. I am not sure whether it is from the exported variables or from the exported functions.

I will write the parts that I want help with first!

p.s. Man I hate this automated tagger!!!!!

* Environment: Windows, Language: C


-------EXPORTING A FUNCTION FROM THE EXE TO THE DLL. (What am I doing wrong here? Cuz mine doesn''t seem to work!!! )
This piece of code is in the EXE''s header file.

__declspec(dllexport) RETURNVALUE	MYFUNCTION( parameters )



这段代码在DLL的头文件中.



This piece of code is in the DLL''s header file.

__declspec(dllimport) RETURNVALUE     MYFUNCTION( parameters )



最后,我将"MYEXE.lib"添加到YOURDLL项目的其他依赖项中.

-------将变量从EXE导出到DLL. (我也在这里也需要帮助)



Finally I added the "MYEXE.lib" to the additional dependencies YOURDLL project

-------EXPORTING A VARIABLE FROM THE EXE TO THE DLL. (I need help here too)

//structuretype_t is an alias to structuretype_s
// but I don't know why in hell do I need to write the word struct with one and not the other to shut the compile up ><'
__declspec(dllimport) structuretype_t		MYVAR2;///
__declspec(dllimport) struct structuretype_s	*pMYVAR2;//




------------------------以下正在工作!所以请忽略,仅供参考!
*回调功能:




------------------------Below is working! So please ignore, placed for reference only!
* Callback functions:

//Note: CAPS user-custom-specific namings.
// if caller is EXE to DLL you need to use either __cdecl or __stdcall somewhere, but I'm not sure where and which.
// parameters: is the ones of the function you want to call back to.
// NOTE: if parameters is noting but "void" then leave the brackets empty.
// I used a personal convention such as CB for Callback, use whatever you like instead.
typedef void (* func_FUNCTIONNAME )(parameters); 
void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME, parameters );// CB: Callback
//void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME );// use this one if the parameters were "void"

void caller_function( void )
{
	func_FUNCTIONNAME pFUNCTIONNAME;
	HMODULE hLib;
	hLib = LoadLibrary(TEXT("YOURDLL.dll"));
// lines of code
	pFUNCTIONNAME = (func_FUNCTIONNAME)GetProcAddress(hLib, TEXT("FUNCTIONNAME"));
	if ( pFUNCTIONNAME == NULL) {
    return;
//Lines of code
	CB_FUNCTIONNAME(pFUNCTIONNAME, parameters);// Calling to the callback function here.
	CB_FUNCTIONNAME(pFUNCTIONNAME);// Use this if there were no parameters.
}

// the definition of the callback function
void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME, parameters )
//void CB_FUNCTIONNAME( func_FUNCTIONNAME pFUNCTIONNAME ) // use this one if the parameters are void
{
    pFUNCTIONNAME( parameters );// leave brackets empty if the parameters are void
    return;
}

//finally, the add __declspec(dllexport) at the start the definition of the function you are calling back too. For example:
__declspec(dllexport) void CallBackToMe( void )
{
//do nothing
 return;
}



-------将变量从DLL导出到EXE.
我没!我添加了一个附加功能来处理变量的编辑.我很幸运,程序中没有指针变量! (^ o ^)/


Reference1:从内部调用EXE函数DLL [ ^ ]
Reference2:我使此回调函数出了什么问题? [ ^ ]



-------EXPORTING A VARIABLE FROM THE DLL TO THE EXE.
I didn''t! I added an additional function to handle editing the variables. I was lucky to have no pointer variables in my program! (^o^)/


Reference1: Calling to an EXE function from inside a DLL[^]
Reference2: I made this callback function what is wrong?[^]

推荐答案

我很困惑:您希望我们为您写一个提示/技巧,因为您无法获得提示/技巧它有效吗?

而不是采用您的"tutuorialish"风格(我感到困惑)-为什么您不只是写下您的问题,并解释您的问题是什么?

哦!我知道!这是因为您昨天这样做了,对试图帮助您的人无礼,并希望我们没有注意到!聪明!

我使此回调函数出了什么问题? [ ^ ]
I''m confused: you want us to write a Tip/Trick for you because you can''t get it working?

Rather than doing your "tutiorialish" style - which I find confusing - why don''t you just write out your question, and explain what your problem is?

Oh! I know! It''s because you did that yesterday, were rude to people who tried to help you, and are hoping we didn''t notice! Clever!

I made this callback function what is wrong?[^]


这篇关于导出函数和变量,请帮助创建模板(重新访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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