| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ and WinAPI Discuss Windows API related issues using C++ (and Visual C++). This is a non-MFC forum. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
--------------------------------------------------------------------------------
hello I have a question.. I realized that when I compiled and made export functions in dll with 'extern "C" __declspec(dllexport)', function names didn't include underscores in front of their name. but I heard that symbols of c functions should include underscores.. is it a just a feature of Visual C++ compiler? Even in import and export sections(in EXE , DLL), the function name doesn't contain underscores in front of its name. but when I compiled function with __stdcall, function name was like _functionName@parametersize and that's exactly like what I learned before.. naming rule of __cdecl functions in C has been changed ? or is it a just matter of compiler ? and one more question.. when we use standard API in kernel32.dll, user32.dll, gdi32.dll and so on even if most functions are standard call functions, the function name is not like _anyName@parametersize .. why ? were they not made by __declspec(dllexport) ? I need help.. I've found no answers that meets my questions.. thanks |
|
#2
|
||||
|
||||
|
Re: I have a question on extern "C"
Post your code. That should work (if I remember my syntax correctly).
Viggy |
|
#3
|
|||
|
|||
|
Re: I have a question on extern "C"
Dear friend,
By adding this " __declspec(dllexport) " statement indicates that the function is to be exported , and __declspec is a standard calling convention. Thats all , it wont add and "Underscores" during function decoration. What Extern "C" means , follow the "C" name decoration standards, Which doesn't add any extra characters in function decoration. I Think you got it. Thakns. |
|
#4
|
||||
|
||||
|
Re: I have a question on extern "C"
Quote:
Let's see some details by example. Code:
// 23.cpp
extern "C" __declspec(dllexport) void foo() {}
Code:
cl 23.cpp /link /dll /map:23.map /out:23.dll Code:
; 23.map 23 Timestamp is 4af1883c (Wed Nov 04 16:57:16 2009) Preferred load address is 10000000 Start Length Name Class 0001:00000000 000063f4H .text CODE 0002:00000000 000000f4H .idata$5 DATA . . . 0003:00000000 00000cd0H .data DATA 0003:00000ce0 00000bbcH .bss DATA Address Publics by Value Rva+Base Lib:Object 0000:00000000 __except_list 00000000 <absolute> 0000:00000003 ___safe_se_handler_count 00000003 <absolute> 0000:00000000 ___ImageBase 10000000 <linker-defined> 0001:00000000 _foo 10001000 f 23.obj <-- symbol 0001:00000005 __CRT_INIT@12 10001005 f LIBCMT:dllcrt0.obj 0001:000002d4 __DllMainCRTStartup@12 100012d4 f LIBCMT:dllcrt0.obj Code:
D:\Temp\23>exports 23.dll
ModuleType:
PE executable (DLL)
Subsystem:
Win32 GUI
ModuleName:
23.dll
Exported Info: BaseOfOrdinals = 1
NumberOfNames = 1
NumberOfFunctions = 1
RelVirtAddr Ord Hint ExportedFuncName
0x00001000 1 0 foo <-- export name
Last edited by Igor Vartanov; November 4th, 2009 at 09:28 AM. |
|
#5
|
||||
|
||||
|
Re: I have a question on extern "C"
Let's see another case, a bit different comparing to the previous one.
Code:
// 23.cpp
extern "C" void foo() {}
Code:
; 23.def
LIBRARY 23.dll
EXPORTS
oops = foo ; here's the trick
Code:
cl 23.cpp 23.def /link /dll /map:23.map /out:23.dll Code:
23
Timestamp is 4af18d73 (Wed Nov 04 17:19:31 2009)
Preferred load address is 10000000
Start Length Name Class
0001:00000000 000063f4H .text CODE
0002:00000000 000000f4H .idata$5 DATA
0002:000000f4 00000004H .CRT$XCA DATA
. . .
0002:0000152c 000000f4H .idata$4 DATA
0002:00001620 00000452H .idata$6 DATA
0002:00001a80 0000003eH .edata DATA
0003:00000000 00000cd0H .data DATA
0003:00000ce0 00000bbcH .bss DATA
Address Publics by Value Rva+Base Lib:Object
0000:00000000 __except_list 00000000 <absolute>
0000:00000003 ___safe_se_handler_count 00000003 <absolute>
0000:00000000 ___ImageBase 10000000 <linker-defined>
0001:00000000 _foo 10001000 f 23.obj
0001:00000005 __CRT_INIT@12 10001005 f LIBCMT:dllcrt0.obj
0001:000002d4 __DllMainCRTStartup@12 100012d4 f LIBCMT:dllcrt0.obj
0001:000002f5 __amsg_exit 100012f5 f LIBCMT:crt0dat.obj
0001:00000319 ___crtCorExitProcess 10001319 f LIBCMT:crt0dat.obj
. . .
Code:
D:\Temp\23>exports 23.dll
ModuleType:
PE executable (DLL)
Subsystem:
Win32 GUI
ModuleName:
23.dll
Exported Info: BaseOfOrdinals = 1
NumberOfNames = 1
NumberOfFunctions = 1
RelVirtAddr Ord Hint ExportedFuncName
0x00001000 1 0 oops
Last edited by Igor Vartanov; November 4th, 2009 at 09:32 AM. |
|
#6
|
|||
|
|||
|
Re: I have a question on extern "C"
Thanks for your kind reply
![]() U seem to have understood what I wondered But I have another question Where's the mechanism that links symbol name (like _anyFunc) with exports name(like anyFunc) ? That is, What can make loader find proper exports name when there's symbol like _anyfunc ? Exports name can be various when there's only one symbol name . The secret is in lib file ? Last edited by EnthusiasticNewbie; November 8th, 2009 at 12:28 PM. |
|
#7
|
||||
|
||||
|
Re: I have a question on extern "C"
Sure. This is exactly what import library is for. Just take a look inside some, and you find the symbol bound to export name. Though the second case will look more tricky.
|
|
#8
|
|||
|
|||
|
Re: I have a question on extern "C"
really thanks for your great explaination
but I couldn't find any linkage in import library file.. there are only symbol names.. no exports name in it! I wonder why.. but I understood that lib file is the only thing that can link symbol and exports name even if I couldn't see what it is.. anyway thanks again
Last edited by EnthusiasticNewbie; November 8th, 2009 at 12:33 PM. |
|
#9
|
||||
|
||||
|
Re: I have a question on extern "C"
Code:
0000000600: 20 20 20 20 20 20 31 32 │ 35 37 39 36 33 38 34 34 1257963844
0000000610: 20 20 20 20 20 20 20 20 │ 20 20 20 20 20 20 30 20 0
0000000620: 20 20 20 20 20 20 33 32 │ 20 20 20 20 20 20 20 20 32
0000000630: 60 0A 00 00 FF FF 00 00 │ 4C 01 44 01 FB 4A 0C 00 `◙ яя L☺D☺ыJ♀
0000000640: 00 00 00 00 08 00 5F 66 │ 6F 6F 00 32 33 2E 64 6C ◘ _foo 23.dl
0000000650: 6C 00 │ l
|
|
#10
|
|||
|
|||
|
Re: I have a question on extern "C"
Thanks
![]() and thanks for my another question on ReadProcessMemory too ! |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|