- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Im now trying to load a DLL dynamically. I read somethings about it and made a try with the following code
program explicit_dll
implicit none
INTEGER :: hLib, iSt
integer :: intZahl
INTERFACE
SUBROUTINE func(intZahl)
integer :: intZahl
END SUBROUTINE
END INTERFACE
POINTER(lpfnfunc,func)
hLib = LoadLibrary("explicit_dll.dll"C)
lpfnfunc = GetProcAddress(hLib,"func"C)
CALL func(intZahl)
iSt = FreeLibrary(hLib)
end program explicit_dll
butI allways get errors like
This name does not have a type, and must have an explicit type. [FREELIBRARY]
I dont konw where my mistake is
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
bjoern_:
hmm sorry got another stupid question.
Why there is allways a C in the LoadLibrary and GetProcAddress command ?
LoadLibrary(hLib,"dllname.dll" C ) this I mean.
I couldnt notice a difference when I omit the C.
anthonyrichards:
Because the function you are calling is a C-function, and itexpects a C-string argument, which is a string of characters terminated by the 'null' character. Typing "a character string"C in your code lets the compiler know that it is to add null character to the end at compilation time. The effectis the same as doing this:
string="a character string"//CHAR(0)
LoadLibrary(hLib, string)
I haveto bring upthis topic once again.
Since today Iam wondering if the "xx"C or the //char(0) command are compiler dependent?
Because I have to wirte a little tutorial and I got to the point where to describeLoadLibrary() etc. the "xx"Cthisquestion came up.
Because I thougt about what is when the "xx"C command is compiler dependent? How can I do it when my program has to be compiler independet? Which mine should be.
I read something about it in this forum and I think understood that this "xx"C command is compiler dependen but //char(0) it not. Am I right or wrong?
I refer to this thread http://softwareforums.intel.com/ISN/Community/en-US/forums/permalink/112062/112048/ShowThread.aspx#112048
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay Thanks.
This may be is annoying to you but I have to ask one more thing.
When I want to explicit link a DLL I have to use the command "use kernel32". So I read something about kernel32. I found out that this is a windows standard DLL which handles memory and some more things. And of course includes the api functions LoadLibrary, FreeLibrary and GetProcAddess which I need to use explicit linking.
So now Im wondering when the kernel32 is a DLL how can I use this DLL when I need this DLL to call a DLL explicit.
This may sound confusing to you please say something when you dont understand what I want to say :)
After my gread confusing theory I tried to figure out how it is possiblie. And I found something. In the project settings under the link tab there is the kernel32.lib quoted. So my idea was that the kernel32 is linked implicit so that I can explicit link my DLLs. And the use kernel32 command says the compiler that he has to link the kernel32.dll to the project else he wouldnt.
So is my theory right or can someone explain it simple. Simple because my english is not that good :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
NO. "use kernel32" just instructs Fortran compiler to take a look at the kernel32.mod, so that it can get proper INTERFACEs to correctly generate the calling sequences. By itself, it doesn't dictate how kernel32.dll will be loaded.
That being said, it's pretty much impossible to write a useful program which doesn't use functions from kernel32.dll explicitly or implicitly (Fortran (and C++ and...) run-time libraries will implicitly load it even if you don't want it, so you would have to get rid of default RTL first, etc.). I might give it a try, but to be honest, I'm lazy to do it, as I don't see what possibly useful it would bring. It is loaded by default with pretty much all the Windows processes, so it's fairly pointless to do a LoadLibrary for it. You can always get its handle through GetModuleHandle("kernel32.dll"//char(0)) if you need to bind its functions dynamically (again, I don't see why).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay thanks.
So when I understand you right, then the kenrel32.dll is allways implicitly loaded to my program. Right or wrong?
And the use kernel32 command is used to get proper INTERFACEs for calling routines from my DLL. If I wouldnt use the kernel32 than I had to write the INTERFACEs by myself to handle the DLL correct. Right or wrong?
Sorry if I act stupid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »