Ecere SDK/eC Forums • View topic - DLL issue




Ecere SDK/eC Forums

Ecere Developers Community

DLL issue

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.

DLL issue

Postby samsam598 » Wed Mar 14, 2012 3:57 am

Greetings!

I created a dll file which contains an function as I described in another threadhttp://www.ecere.com/forums/viewtopic.php?f=5&t=224
inputbox.ec:
Code: Select all
 
import "ecere"
int InputBox(){...}//InputBox will open an GUI dialog
 


client code:
Code: Select all
 
import "inputbox"
import "ecere"
void test()
{
    int num=InputBox();
}
 

Now I want to make use of this dll in my project.Following the Tao I finally make my program running.But I doubt whether the full source code for this module is necessary,shouldn't it be the same as C libraries that only a header file contains function signature should suffice?

Thanks for the help in advance.

Regards,
Sam
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: DLL issue

Postby jerome » Wed Mar 14, 2012 11:04 am

Hi Sam,

I'm not sure what your question is here?
Your code looks right. Which 'full source code' are you referring to?

eC modules are 'imported'.
This ensures that the shared modules have their eC symbols initialized, and takes away the need to link them using the linker (You do not need to add the dll to the 'Additional libraries' in the project linking settings).

import "inputbox" is all you need, and as you probably found out you need to make InputBox() public, and the dll location to your PATH (Compiler Executable dirs -- Windows) or LD_LIBRARY_PATH (Library dirs -- Linux), or copy it to your "client" project directory.

You can link C or C++ code, or even eC code that does not use any special OO stuff, using C headers and the traditional linker way, but not object oriented eC code (Because each eC module -- shared library -- has to get initialized through the importing mechanism). On Windows though this is painful, you have to use dllexport. Which is why the eC importing mechanism makes everything much easier :D

Please let me know if you have any other questions regarding this :)

Regards,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: DLL issue

Postby samsam598 » Wed Mar 14, 2012 7:49 pm

Sorry for not make it clear.

As I've already made the module dll,I think below codes suffice:

imported module file inputbox.ec:
Code: Select all
 
 
int InputBox();
 

I assume above is all what I need to add to my client project,please correct me if I was wrong.

client code:
Code: Select all
 
import "inputbox"
import "ecere"
 
void test()
{
    int n=InputBox();
}
...
 


But actually I found the complete source code for what I've implemented the InputBox() is necessary to keep in the inputbox.ec file when I try call dll in my client code.This is what I am wondering.

Hope it is clear,but not sure,sorry...

Regards,
Sam
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: DLL issue

Postby jerome » Wed Mar 14, 2012 11:02 pm

Hi Sam,

Sorry, I'm even more confused now :)

If you want to define the input box in a dll, and use it in another executable project, you need two projects. The InputBox project will have one .ec file with the inputbox code (e.g. inputBox.ec).

Code: Select all
import "ecere"
 
public int InputBox()
{
   int num;
   FormInteger form{};
   incref form;
   form.Modal();
   num=form.number; 
   delete form;
   return num;
}
 
class FormInteger : Window
{
   caption = "整数:";
   background = activeBorder;
   borderStyle = fixed;
   size = { 368, 148 };
   anchor = { horz = -107, vert = -153 };
 
public:
   int number;
   property int number
   {
      set { number=value; txtNumber.Refresh(); }
      get {return number;}
   }
   Button btnOK
   {     
      this, caption = "OK", altO, isDefault = true, size = { 74, 21 }, position = { 256, 80 };
      NotifyClicked = ButtonCloseDialog;
   };
   Label lblTxtNumber { this, labeledWindow = txtNumber, size = { 140, 13 }, position = { 16, 8 } };
   SavingDataBox txtNumber { this, caption = "请输入整数:", data = &number, type = class(int), size = { 326, 19 }, position = { 16, 32 } };
}


The name of the project and the source file could be different, but note that it is the project name (and target dll name) that must be used to import it into your client executable.

Then your project will have one or more file, where you will import the inputbox module where you need it. That project should not have inputbox.ec included in it. (You want to import from the dll, not the .ec file):

Code: Select all
import "ecere"
import "inputBox"
 
class App : GuiApplication
{
   bool Init()
   {
      InputBox();
      return true;
   }
}


You will need to copy the built dll to the client project's directory for it to compile (The compiler will load the InputBox.dll when compiling your client code to see what classes/functions are defined in there).

You should never have to write C-style prototype declarations for eC code as in your first code block...

I hope this is clearer :)

Cheers,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: DLL issue

Postby samsam598 » Wed Mar 14, 2012 11:13 pm

Thanks for your prompt reply,please see my comments below to see if you can get it.Thanks.


Sorry, I'm even more confused now :)

Then your project will have one or more file, where you will import the inputbox module where you need it.

That project should not have inputbox.ec included in it.Sam: I've expected so but the compiler complains can't find reference to InputBox().(You want to import from the dll, not the .ec file):

Code: Select all
import "ecere"
import "inputBox" //Sam: So no inputBox.ec source file needed in this project?class App : GuiApplication
{
   bool Init()
   {
      InputBox();
      return true;
   }
}


You will need to copy the built dll to the client project's directory for it to compileSam:Sure I did it.

You should never have to write C-style prototype declarations for eC code as in your first code block...Sam: I have expected so but without the complete source of inputbox.ec my test project cann't find reference to InputBox().
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: DLL issue

Postby jerome » Wed Mar 14, 2012 11:36 pm

Hi Sam,

Please find attached example projects, and tell me what you're doing differently :D

Regards,

Jerome
Attachments
inputBoxDll.7z
Using an eC DLL example projects
(19.82 KiB) Downloaded 1088 times
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: DLL issue

Postby jerome » Wed Mar 14, 2012 11:42 pm

Note, if you have both project building in the same directory, the compiler might be confused whether you want to import InputBox.dll or InputBox.ec!

You need to use separate names or separate folders.

-Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm

Re: DLL issue

Postby samsam598 » Thu Mar 15, 2012 1:24 am

jerome wrote:Hi Sam,

Please find attached example projects, and tell me what you're doing differently :D

Regards,

Jerome

This is exactly the same what I have thought and what I have done.My previous failure experience is mainly due to :
1.inputbox.dll should be copied to the project folder ,not the project/obj/release.win32/ folder,I've done wrong here;
2.when I copied inputbox.dll to the project folder and re-compiled,it failed as well.This time is because during my very first attempt,I wrote inputbox.ec file with a blank inputbox() in it.So this time the build system found it.

After I deleted inputbox.sym,move the inputbox.dll from release.win32 folder to the project folder,everything became fine now.

Thank you so much!

Regards,
Sam
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: DLL issue

Postby jerome » Thu Mar 15, 2012 1:40 am

Ah yes :) Glad you could figure it out.
Sorry that it's not so obvious.

The 'project' folder is always the current folder for the IDE, for running/debugging application as well, so that all configurations run in the same directory.

Although if you put a dll in the executable's folder, it will be given priority over the project folder, and over 'additional projects' as well.

After you have created both projects, you can add your 'dll' project to your executable project's workspace, and the active configuration of that project will be the dll that gets picked up by default (assuming you do not put any dll inside the obj/release/win32/). However it won't get picked up for compiling, one thing you can do for that is specifying your dll obj/release.win32/ path in Global Settings->Compiler->Executable path. You can compile against the release dll and run with the debug dll no problem (e.g. when the 'Debug' configuration of your project is selected). This way you do not need to copy any dlls around (and you're always sure to be running with the latest!).

Regards,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm


Return to GUI Toolkit & 2D Graphics

Who is online

Users browsing this forum: No registered users and 6 guests

cron