开发者

compiling in visual studio 2005 and visual C++ 6.0

  1. What is the difference of creating a simple C DLL between using visual studio 2005 and visual C++. I saw that when creating it under studio also a manifest was created and I had some problems regarding deployment in another machine because of using side-by-side folder (when ca开发者_开发知识库lling that dll form a C# application"
  2. How does the mechanism of calling a dll work ?

Thanks


Yes, if you compile the DLL's code with /MD (the default setting) then you have to deploy the CRT libraries to the target machine. If this is just a standalone DLL without any other dependencies then it makes sense to compile with the static CRT option so you don't have to deploy the libraries. Right-click your DLL project, Properties, C/C++, Code Generation, Runtime Library = /MTd for the Debug configuration. Repeat for the Release configuration, now using /MT.

Google "P/Invoke marshaling" to learn more about how unmanaged code is called from a managed program.


Since nobugz already covered your first question, let me expand on the second. It's not terribly difficult to understand.

When you compile a DLL in Windows, the linker creates an Export Address Table (EAT) that lists all the the exported functions (the functions the DLL provides) and a pointer to where they are implemented in the DLL itself.

When compiling a application that links to a DLL, the linker creates an Import Address Table (IAT) listing all the functions that are implemented in other DLL's and the name of the DLL that implements those functions. The way it knows that a function exists in a DLL is from the .lib file that you add to your project. That tells the linker that a function is implemented in a DLL.

Then at run time, while loading an application the Windows loader examines the IAT to see what DLL's need to be loaded, locates them, and updates the applications IAT (in memory) to point to the exported functions in the DLL's loaded.

That's the basics how it works, hopefully I didn't include any gross inaccuracies. And of course P/Invoke is another layer on top of this.

If you want more information on how DLL's work there is always the MSDN documentation and if you want enough detail to make you head spin read these Inside Windows articles Part 1 and Part 2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜