Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ DLL netbeans
how can I consume a dll in my c++ code written in netbeans 7.3 ?
Posted 1-Apr-13 20:05pm
AsthaS453
Comments
Sergey Alexandrovich Kryukov at 2-Apr-13 1:32am
   
Why not asking this question on the page where you asked about creation of DLLs, your previous question. in a comment to an answer or using "Improve question"?
This is almost a re-post. Your next question will be what? How to set a calling conventions? Export/Import a class? A separate question per topic?
—SA
AsthaS at 2-Apr-13 2:25am
   
I am new to this forum and mind you i wasn't aware that this forum had such norms.
Richard MacCutchan at 2-Apr-13 4:12am
   
You don't 'consume' a dll (whatever that may mean), you link it to an executable program. If you do not understand such basic issues then you should focus on some simpler programming issues first.
AsthaS at 2-Apr-13 5:12am
   
Consume is just a word that i used...My purpose for posting this question was just to get my problem solved(which I am not able to find yet) and not to get instructions for what to do and what not to...
PS- don't take it personally..but i really want a solution thats it.
Matthew Faithfull at 2-Apr-13 7:06am
   
Ahh, I see that I missed your follow up question when I replied to your previous question and suggested posting a follow up. Sorry it doesn't look like that went too well. You need to try something first, implicit linking is easiest, so that you have code to post with your question if you get stuck. It would help to the name of your Dll and the Exe that you are linking it to and a specific function in one that you are trying to call from the other, which way round you want to make the call and where any custom parameter types are defined.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I'm guessing you probably didn't want to post your code as a solution but never mind. There are a few odd things here but I don't know for sure if any of them are the cause of the error message you're seeing.
You're using Dynamic/Late/Runtime/Explicit loading of the Dll in this code which is fine, it means that you should be able to run the code in Debug and set a Breakpoint to stop execution before the error occurs. If you can do this there's a very good chance of solving the problem.
 
The first thing is that hGetProcIDDLL needs to be checked to see if you actually managed to load the Dll, given that you say the Dll is called 'MyDll' and the file name you've tried to load is 'libCppApplication_1' I would say that's unlikely.
 
Once the Dll is loaded there's the call to GetProcAddress. Your way of casting is slightly unconventional and may cause confusion. I prefer the long hand explicit C++ cast for these scenarios especially for test code.
 
FARPROC lpfnGetProcessID = GetProcAddress( reinterpret_cast< HMODULE >(hGetProcIDDLL),"demo");
 
There's one further issue with this related to calling convention. Your code comments state that the function uses __stdall Pascal convention. Confusingly this is stated as for maximum compatability, unfortunately __stdcall has very poor compatability especially between Microsoft and Borland compilers. If the Dll does in fact export this function as __stdcall then the name is likely but not certain to have an "_" automatically prepended to it making it "_demo" or even "__demo". This depends on which compiler you're using on the back end of Netbeans and if it's GCC what options Netbeans is passing through to it.
 
To avoid these horrible "_" issues either change the Dll to use __cdecl 'C' calling convention or examine the Dll binary with a tool like depends to determine exactly what name the compiler has exported.
 
Once you get this far and actually have a function pointer for your function the rest should go smoothly. If you get into any trouble remember the simple rule. The module that allocates must be the module that frees In other words don't allocate anything, then pass it, then free it in the module it was passed into.
 
Happy Dlling
  Permalink  
Comments
AsthaS at 5-Apr-13 8:27am
   
Thanxx Matthew...After a bit of roaming around the facts..I have finally done it..!!
Matthew Faithfull at 5-Apr-13 8:31am
   
Congrats. Now your future projects can have great modular architecture.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 341
1 Marcin Kozub 225
2 Praneet Nadkar 197
3 Sergey Alexandrovich Kryukov 190
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100