![]() |
|
#1
|
||||
|
||||
regarding dll creation and "work with"Hey guys,
Just came back from army reserve, missed you guys ! (though I see Paramesh is taking care of all the threads I subscribed to The question : Given the function prototype : CPP / C++ / C Code:
and say I implemented this function somehow - How do I create a dll that contains this function ? How do I use the function from the dll ? Obviously (as you know me ... ), I am talking about ansi-c code only - if it matters. Shabat shalom, Kobi Hikri. __________________
It's actually a one time thing (it just happens alot). |
|
#2
|
||||
|
||||
How to create and use a DLL In a C programHi Kobi,
I just learnt how to create and use dll in files. Here is what i found:
Now, onto using the dll in our project.
CPP / C++ / C Code:
This error comes only in Visual C++. Not in Dev C++. Sorry about the error. I'm still googling to find out what is the error, and still unable to find out how to solve the error. (I'm new too!) Do anyone know how to solve this error? Note that this is only one method of creating and using a DLL. Regards, ![]() Paramesh. PS: Kobi, i have written from basics because everyone would understand __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
||||
|
||||
Re: How to create and use a DLL In a C programHey Paramesh.
Thank you very much for your attention. Quote:
And I'm glad you did Check this out : Simple dll (this is actually what you explained, even less ... ) Here is something more like what you explained : Create and use dll When you learned this topic, did your instructor teach you if we must include windows.h ? Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#4
|
||||
|
||||
Re: How to create and use a DLL In a C programKobi,
The links you told were exactly what i referred. and i found why the error comes up. Because: I declared the DLL with a different calling convention than the function pointer. In Visual C++, we have __cdecl and __stdcall calling conventions. We must declare your function pointer to match the proper calling convention as the DLL function. The WINAPI i used is __stdcall, but the DLL function is a __cdecl function. I should make sure that the DLL and app both declare the DLL function as __cdecl or __stdcall (We have a choice in which one to fix). If we were to fix the DLL, we would do this: CPP / C++ / C Code:
Then the declaration of WINAPI for the function pointer in the app would match the DLL function's calling convention (in this case __stdcall). If we want to change your DLL, then the app should declare a __cdecl function pointer (in this case,there is no need for the WINAPI -- just declare an "ordinary" function pointer (no WINAPI), since ordinary C functions are automatically __cdecl). The calling convention determines how the parameters are passed to the function (which parameter actually goes first on the stack), and which function is responsible for cleaning up the stack. A mismatch in calling convention causes the error. And we should check what is the name of the exported function. It may vary. To see what the name is, we should use the Dependency Walker utility (depends.exe) and look at the exported names. So, here is my final code: DLL: fact.cpp: CPP / C++ / C Code:
fact.def: Code:
I used the dependency walker utility and found that the function name was: _fact@4 (because the return bytes is 4(int)) Calling program: main.cpp CPP / C++ / C Code:
The output came without any errors: Code:
Note that the function name is found using the dependency walker utitlity, by opening the fact.dll. The sample look at the fact.dll opened with the dependency walker utility is in the attachment: Quote:
Why did you ask this? Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#5
|
||||
|
||||
Re: How to create and use a DLL In a C programQuote:
Oh ..., I don't get it ... Why don't you have instructors ? Anyway, my question about windows.h came because I'm looking for a way to create function library's (or something that will act like a function library) in my OS project, so that the user could use some built in functions (I will supply all of them). I don't want to use windows.h for my OS So, I asked about it because I assumed you learned this topic at class, and perhaps this point came up. Do you suppose this is possible ? Anyway, Paramesh - your help is appreciated and I'll have to re-think my design. (The problem with hobbies is that you never have enough time to dedicate to it - so this OS project is not advancing as I wish). Well, if we're talking about time, then it's time for me to go to work Kobi. __________________
It's actually a one time thing (it just happens alot). |
|
#6
|
||||
|
||||
Re: regarding dll creation and "work with"Kobi,
Sorry about not using ANSI C. Of course, we have instructors for all subjects. But since we dont learn C/C++ in detail(they taught us 2 years ago) , i told you that I dont have an instructor now for Computer related subjects. I think(not sure): If you dont want to use windows.h, you should forget about dlls. Linux has .so extension for dynamic libraries. May be these link can give you some information: Writing Dlls for Linux Apps Dynamically loaded libraries in Linux I'll try to find more information about this. Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The