青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

concentrate on c/c++ related technology

plan,refactor,daily-build, self-discipline,

  C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
  37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

常用鏈接

留言簿(9)

我參與的團(tuán)隊(duì)

搜索

  •  

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

這回貼上來(lái)自codeguru上面的一篇討論,感覺(jué)很舒服:
   

I’ve created a very simple Win32 DLL. It only has one exported function called “Test” whose declaration looks like this:-

#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif


MYDLL_API HRESULT Test(void);
Then in the source file:-

MYDLL_API HRESULT Test(void)
{
return (HRESULT) 66;
}


Now in my executable, I’ve done this:-

static HMODULE hDLL;
typedef HRESULT (STDAPICALLTYPE * LPFNTEST) (void);
LPFNTEST _pfnTest;

Then I load the DLL:-

hDLL = LoadLibrary("MyDLL.dll");

All the above works fine and hDLL gets a non-NULL value . Now I come to obtain the proc address for function “Test”:-

_pfnTest = (LPFNTEST)::GetProcAddress(hDLL, "Test");
but _pfnTest ends up as NULL and GetLastError() returns 127 (ERROR_PROC_NOT_FOUND). What have I done wrong?? I haven't implemented any code yet in DllMain(). For example, I haven't initialised anything. Should I have done?


Siddhartha

February 20th, 2006, 11:18 AM

but _pfnTest ends up as NULL and GetLastError() returns 127 (ERROR_PROC_NOT_FOUND). What have I done wrong?? You have not accounted for the name decoration that the VC++ Compiler has subjected your DLL's Exported Functions to.

To know exactly what it has done, open the DLL in Dependency Walker and observe exported function names...

www.dependencywalker.com (http://www.dependencywalker.com) (for latest version)
You either need to GetProcAddress of the functions using their decorated names, or better - create entries in your DLL Project's DEF File that define the names of the exported functions the way you would like to see them as.

Something like this -
LIBRARY "MYDLL"

EXPORTS
Test PRIVATE


Bornish

February 20th, 2006, 11:18 AM

Your function is exported using the C++ decorated name. Use extern "C" before the function prototype, or use a *.def file in your project containing:EXPORTS
TestTo know for sure that your function is exported with an undecorated name, use Dependency Viewer to list its exports.

Note: I've noticed another potential problem, which will not affect this test function since has no parameters, but your dll declares the function as __cdecl (depending on your project's default settings), and the exe tries to use it with STDAPICALLTYPE which I assume stands for __stdcall calling convention.

Regards,


John E

February 20th, 2006, 11:31 AM

Thanks guys. It's ages since I wrote a DLL. It's all starting to come back to me now!! :wave:


John E

February 23rd, 2006, 04:51 PM

Hmmm.... this still isn't quite right. According to this MSDN article (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_20.asp) the use of dllimport and dllexport should eliminate the need to specify exported functions in a module definition file (.DEF)

However, in my case, that's not working. I'm finding that I still need to list the functions as EXPORTS in a .DEF file - even though I'm correctly defining __declspec(dllimport) and __declspec(dllexport). Any ideas about what I might be doing wrong?


Paul McKenzie

February 23rd, 2006, 05:06 PM

Hmmm.... this still isn't quite right. According to this MSDN article (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_20.asp) the use of dllimport and dllexport should eliminate the need to specify exported functions in a module definition file (.DEF)Only if you are linking with the export library, in other words, you're using Visual C++ and you add the .lib to your project.

If you're using LoadLibrary() and GetProcAddress(), there is no .lib file to help the linker resolve the name. You must either use the *exact* name you see in the exported function list when you ran Dependency Walker, or you use a def file and rebuild your DLL to get a totally "clean" function name.

Regards,

Paul McKenzie


Bornish

February 23rd, 2006, 05:07 PM

If you use __declspec(dllexport) you don't need the def file.
In fact, with only a def file you might get into an ambiguous name situation (like it happen to me before), when a class declared a method with the same name of the global exported function. The solution was to use __declspec(dllexport) for the global function.
The problem we suggested you might have was that your function was exported with a C++ decorated name. Thus, you need to use extern "C" before __declspec(dllexport).
Got to go now... :)
Regards,


John E

February 23rd, 2006, 05:22 PM

Only if you are linking with the export library, in other words, you're using Visual C++ and you add the .lib to your project.You mean if I link statically, rather than dynamically?

Surely if I link statically, there's no need to mess about with dllimport and dllexport at all??


VladimirF

February 23rd, 2006, 05:28 PM

Paul wasn't talking about static link, he compared dynamic linking with on-demand GetProcAddress() call.


kirants

February 23rd, 2006, 05:36 PM

Hmmm.... this still isn't quite right. According to this MSDN article (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/msmod_20.asp) the use of dllimport and dllexport should eliminate the need to specify exported functions in a module definition file (.DEF)

However, in my case, that's not working.

I don't think that is the case. It is not working because you are doing a GetProcAddress with non-mangled name while using dllexport without using a def file causes name mangling and hence the failure.

The reason it works when you add the .def file with the names is because you are putting the name in unmangled form in it and that is what you are using in GetProcAddress.

So, summary si this:
if you use dllexport approach without def file, please understand that the Visual C++ compiler mangles the name and this is the form in which your function will be exported. For e.g. your Test function will be exported as , ?Test@XWZ or something of that form. So, if you do a GetProcAddress, make sure you use "?Test@XWZ" and not "Test".
If you use dllexport, but also supply a .def file with the undeclared names, the linker is gonna put that in the dll export section. So, you can now use GetProcAddress(hMod,"Test")
If you do use .def file, there is no need to use dllexport directive
If you do not want to use .def file and still want to use dllexport directive, wrap those functions with

extern "C"
{

}


kirants

February 23rd, 2006, 05:38 PM

You mean if I link statically, rather than dynamically?

A dll is always dynamically linked. What Paul was referring to was implicit linking versus explicit linking via LoadLibrary/GetprocAddress


John E

February 23rd, 2006, 05:48 PM

Thanks for the help. I did realise that the problem was because of decorated names. What I didn't realise was that I had to link to the lib if I used __declspec(dllexport).... I've managed to get it to work now, without the DEF file :wave:


kirants

February 23rd, 2006, 05:52 PM

What I didn't realise was that I had to link to the lib if I used __declspec(dllexport)
No. using dllexport does not mean you have to link to the .lib file.

Whether you use dllexport or def file, you will always be able to use LoadLibrary/GetProcAddress approach , provided you pass the right export name to GetProcAddress


John E

February 23rd, 2006, 05:55 PM

Oops... one other thing, just before I shoot myself in the foot...!

Ultimately, this DLL will be going to someone who'll be calling it from Visual Basic .NET. This means that my lib file would be useless to them. Therefore, I guess I'm better off sticking to the .DEF approach on this occasion because I don't really want the names to be mangled.


MikeAThon

February 23rd, 2006, 11:59 PM

A dll is always dynamically linked. What Paul was referring to was implicit linking versus explicit linking via LoadLibrary/GetprocAddress
I think that Microsoft refers to these as "run-time dynamic linking" vs. "load-time dynamic linking". See http://msdn.microsoft.com/library/en-us/dllproc/base/using_dynamic_link_libraries.asp

Mike


kirants

February 24th, 2006, 12:29 AM

Interesting, Mike.. ... Microsoft seems to be using different terms for the same :)

For e.g. see here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_determine_which_linking_method_to_use.asp


MikeAThon

February 24th, 2006, 01:28 AM

You're right: that is the same thing, and Microsoft is using different terminology for it.

Mike


gopal.srini

February 24th, 2006, 02:49 AM

Hi

Continuing with this topic, could any one please tell me how to call a method from ddao35.dll, say - OpenDatabase whose return type is class- CdbDatabase - using __declspec( dllexport ), they have exported this function available in dbdao.h file

I tried the follwoing but in vain

typedef UINT (CALLBACK* LPFNDLLFUNC1)(LPCTSTR,BOOL,BOOL,LPCTSTR);
LPFNDLLFUNC1 lpfnDllFunc1;
char *get_ver = "?OpenDatabase@CdbDBEngine@@QAE?
AVCdbDatabase@@PBDHH0@Z";

if(hDLL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"?OpenDatabase@CdbDBEngine@@QAE?AVCdbDatabase@@PBDHH0@Z");


if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return 0;
}
else
{
lpfnDllFunc1("TestDB.mdb",0L,FALSE,NULL);
printf("success");

}

I am getting unhandled exception in my.exe(ddao35.dll) 0xc0000005 Access violation

Any help?

Regards
Gopal


kirants

February 24th, 2006, 03:40 AM

gopal.srini, please start a new thread, since this seems to be a different problem and unrelated to the original question


gopal.srini

February 24th, 2006, 04:09 AM

ok..sorry..

Thanks
Gopal


wshcdr

February 24th, 2006, 01:09 PM

To use LoadLibrary(...),GetProcAddr(...) ,you must write a DEF file,


Bornish

February 25th, 2006, 09:56 AM

To use LoadLibrary(...),GetProcAddr(...) ,you must write a DEF file, :eek: This is somehow correct, if one needs undecorated names to be exported.
I thought using __declspec(dllexport) can eliminate the need of a *.def file. :blush:
I've tried exporting a function Test from a DLL that doesn't make use of a def file, so I've wrote this:extern "C" __declspec(dllexport) int __stdcall Test(int x) {
return ++x;
}The result was an export named _Test@4 (C++ decorated), thus extern "C" having no effect. I've tried several other variations... even using the obselete keyword _export in a *.c file instead of a *.cpp file. Still didn't find a way to export my function as Test without using a def file. It seems to be the only way to define alias names when exporting functions or to export only by ordinal (NONAME)... else you'll get the C++ decorated name _Test@4.
Conclusion:
If you don't care less about the name used in GetProcAddress, then you don't need a def file... else, use a def and keep your _declspec(dllexport) to avoid ambiguities. An article from MSDN recomends writing in a def file both the alias name and the decorated name to avoid ambiguities:EXPORTS
Test = _Test@4This way, when another namespace or class defines a function Test, the linker won't have a dilemma in choosing the function to export.
Best regards,


John E

February 25th, 2006, 10:21 AM

You've pretty much confirmed what I found myself. The only way to guarantee that the names don't get decorated is to put them in a .DEF file.

If you go the __declspec(dllexport) route - together with __declspec(dllimport) - then, providing you use Paul's suggestion of linking to the DLL's associated lib file, you can call the functions as though they weren't decorated - but in fact, they still are.

I assume that what the lib must do is simply to translate calls to each function's undecorated name into the corresponding call with the decorated name.

 

 

 

posted on 2008-04-02 16:29 jolley 閱讀(489) 評(píng)論(0)  編輯 收藏 引用

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一本色道久久综合亚洲精品按摩| 欧美激情在线狂野欧美精品| 国产资源精品在线观看| 欧美特黄一区| 国产亚洲永久域名| 国产一区二区久久久| 国内久久视频| 亚洲精品免费在线播放| 宅男噜噜噜66一区二区| 一区二区三区欧美激情| 亚洲欧美国产精品桃花| 香港久久久电影| 久久久久国产一区二区| 欧美国产日本高清在线| 99视频日韩| 久久理论片午夜琪琪电影网| 欧美另类一区| 国产人久久人人人人爽| 在线成人激情黄色| 一区二区三区国产精华| 久久精品99国产精品日本| 欧美va亚洲va日韩∨a综合色| 欧美久久久久久| 猛干欧美女孩| 国产精品久久国产三级国电话系列| 国产精品美女久久久久久久 | 欧美韩国日本综合| 国产精品99一区| 在线观看欧美日本| 午夜精品一区二区三区在线视| 久久这里只有| 亚洲一区二区三区四区在线观看| 久久综合色播五月| 国产精品网站在线| 日韩写真视频在线观看| 久久久亚洲一区| 亚洲一区久久| 欧美三级视频在线| 亚洲老司机av| 欧美成人免费全部观看天天性色| 亚洲性感美女99在线| 欧美大片在线看| 亚洲电影免费观看高清完整版在线观看 | 久久五月婷婷丁香社区| 在线中文字幕一区| 欧美国产极速在线| 亚洲黄色片网站| 免费影视亚洲| 欧美亚洲系列| 国产精品免费久久久久久| 一区二区欧美日韩视频| 欧美激情精品久久久| 久久婷婷丁香| 在线观看国产一区二区| 久久亚洲一区| 久久久久久久一区二区| 韩国免费一区| 麻豆精品在线观看| 久久国产婷婷国产香蕉| 国产亚洲欧美一级| 久久看片网站| 久久综合久久88| 亚洲国产日日夜夜| 亚洲国产精品电影| 久久九九国产精品怡红院| 国产真实久久| 美女脱光内衣内裤视频久久网站| 久久久久久伊人| 91久久精品美女高潮| 最新国产乱人伦偷精品免费网站| 欧美经典一区二区三区| 亚洲在线免费| 久久高清福利视频| 亚洲黄色成人网| 欧美大尺度在线| 欧美福利一区二区| 亚洲欧美综合v| 亚洲免费人成在线视频观看| 午夜精品久久99蜜桃的功能介绍| 久久另类ts人妖一区二区| 欧美亚一区二区| 亚洲区一区二| 久久精品国产一区二区三区| 亚洲区第一页| 亚洲视频在线观看三级| 久久久精品2019中文字幕神马| 欧美人与禽性xxxxx杂性| 亚洲成色777777在线观看影院| av不卡在线| 久久久久国产一区二区三区| 亚洲男人影院| 国产日韩欧美一区二区三区在线观看| 一本色道久久| 亚洲免费观看高清完整版在线观看| 久久久久久69| 亚洲国产裸拍裸体视频在线观看乱了中文| 久久九九国产精品怡红院| 亚洲一区二区欧美| 国产日韩精品在线| 久久久久国产精品午夜一区| 亚洲视频在线看| 国产精品久久久久久久久果冻传媒| 99re视频这里只有精品| 日韩一级大片在线| 国产精品日日摸夜夜摸av| 欧美一级视频精品观看| 亚洲欧美日韩另类| 红桃视频国产一区| 欧美黑人一区二区三区| 久久青草欧美一区二区三区| 亚洲精品视频在线观看免费| 宅男在线国产精品| 亚洲日韩成人| 在线亚洲精品| 欧美成人精品在线视频| 欧美一级午夜免费电影| 亚洲国产精品99久久久久久久久| 亚洲免费精彩视频| 亚洲国产欧美日韩| 欧美在线视频一区二区三区| 一本色道久久88综合日韩精品 | 欧美女同视频| 午夜精品一区二区三区在线视 | 亚洲免费av片| 国产在线不卡精品| 一区二区欧美视频| 亚洲精品欧美日韩专区| 久久er精品视频| 午夜精品免费视频| 国产精品国产三级国产专播品爱网 | 欧美+亚洲+精品+三区| 欧美日韩一区二区三区视频| 亚洲国产精品专区久久 | 欧美性开放视频| 亚洲福利免费| 亚洲成色www久久网站| 久久精品99国产精品酒店日本| 亚洲视频中文字幕| 欧美日韩一区二区三区在线看 | 久久精品国产第一区二区三区最新章节| 性久久久久久久| 久久精品国产999大香线蕉| 国产欧美精品日韩区二区麻豆天美| 国产精品99久久不卡二区| 亚洲无人区一区| 国产亚洲精品高潮| 香蕉国产精品偷在线观看不卡| 亚洲视频一区二区免费在线观看| 亚洲一区国产一区| 欧美视频国产精品| 亚洲影院免费观看| 免费日韩精品中文字幕视频在线| 伊人激情综合| 免费日韩一区二区| 中文国产成人精品| 欧美激情中文字幕一区二区 | 亚洲国产日韩欧美在线图片| 久久久久.com| 91久久一区二区| 久久国产一区| 亚洲电影免费| 国产精品乱码久久久久久| 久久国产精品免费一区| 亚洲福利视频在线| 午夜欧美理论片| 夜夜爽av福利精品导航| 韩国av一区二区三区在线观看 | 久久亚洲精品一区二区| 欧美激情一区二区三区蜜桃视频| 亚洲视频综合| 亚洲人成亚洲人成在线观看| 国产精品国产精品| 久久久久久久久久久成人| 日韩视频一区二区| 欧美高清在线视频观看不卡| 一本不卡影院| 亚洲精品中文字幕在线| 在线看欧美视频| 在线成人av| 精品不卡一区| 在线精品一区| 在线欧美电影| 亚洲电影第三页| 亚洲欧洲另类| 亚洲精品日韩综合观看成人91| 樱花yy私人影院亚洲| 韩日视频一区| 日韩一级网站| 亚洲一区二区三区三| 在线视频欧美日韩| 亚洲欧美另类久久久精品2019| 亚洲一区激情| 在线一区二区三区四区| 一区二区三区欧美在线| 亚洲一级二级在线| 欧美日韩精品一本二本三本| 欧美影院成人| 久久免费国产精品1| 欧美极品影院| 国产在线一区二区三区四区|