dll主要 [英] dll main

查看:85
本文介绍了dll主要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL的错误,我'米试图注入和after.At第一次  DLL_PROCESS_ATTACH:被称为在begining.ie当我称为NBSP;从管理C#应用程序sampleFunction

I had a bug with a DLL that I'm trying to inject and after.At first time DLL_PROCESS_ATTACH: is called at begining.i.e when I called sampleFunction from managed c# application.

但是,当我关闭了应用程序,没有调用$
  DLL_PROCESS_DETACH!

But when I closed application ,
 DLL_PROCESS_DETACH is not called!

以下是我在dllmain.cpp中的代码

Following is my code in dllmain.cpp

/ / dllmain.cpp:定义DLL应用程序的入口点。

#include" stdafx.h"

#include" UFBRepCreator.h"



BOOL APIENTRY的DllMain(HMODULE HMODULE,

           &NBSP ; DWORD  ul_reason_for_call,

             LPVOID lpReserved



{

开关(ul_reason_for_call)

{

< span style ="white-space:pre"> case DLL_PROCESS_ATTACH:

MessageBoxA(NULL," testStart" ,"testStart",NULL);

break;

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

break;

case DLL_PROCESS_DETACH:

MessageBoxA(NULL," DLL_PROCESS_DETACH"," testEnd",NULL);

break;

}

返回TRUE;



} b

extern"C"__ declspec( dllexport)int sampleFunc ()$
{

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "UFBRepCreator.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "testStart", "testStart", NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
MessageBoxA(NULL, "DLL_PROCESS_DETACH", "testEnd", NULL);
break;
}
return TRUE;

}

extern"C"__declspec(dllexport)int sampleFunction()
{

MessageBoxA(NULL," DLL_PROCESS_DETACH"," testEnd",NULL);

MessageBoxA(NULL, "DLL_PROCESS_DETACH", "testEnd", NULL);

返回0;

return 0;

}

我的问题是如何知道进程是否已分离?

My question is how do I know is process is detached?

推荐答案

在处理DllMain期间调用任何不在kernel32.dll中的函数导致错误或问题。  MessageBox函数驻留在user32.dll中。 你不应该从DllMain打电话。 请参阅

动态链接库最佳实践


Calling any function that does not reside in kernel32.dll during the processing of DllMain is bound to result in errors or problems.  The MessageBox function resides in user32.dll.  You should not call it from DllMain.  See Dynamic-Link Library Best Practices

我建议您使用  OutputDebugString函数代替。 您可以在Visual Studio调试器中看到此函数的输出,或者如果不是debuggin
,您可以使用Sysinternals实用程序
Deb ugView

I suggest you use the OutputDebugString function instead.  You can see the output from this function in the Visual Studio debugger, or if not debuggin you can use the Sysinternals utility Deb ugView


这篇关于dll主要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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