April 27, 2024, 10:09:10 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Window in a DLL

Started by aurelCB, March 11, 2012, 03:20:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi...
I need create DLL in which can be opened standard window.
I have search trough forum but don't find anything similiar.
Any ideas are welcome... :)

my code of .dll look like this:
Export MyWindow
Export MyFunc

SUB Mywindow(hWnd:window,hwndX:int,hwndY:int,hwndW:int,hwndH:int,wStyle:int,wParent:int,wCap:string),INT
'INT myW
IF wstyle=0
wStyle=@minbox
ENDIF

RETURN OPENWINDOW hWnd,hwndX,hwndY,hwndW,hwndH,wStyle,wParent,wCap,&Mysub

ENDSUB

SUB MySub
'winMSG = @MESSAGE

OnMessage #<window>@Hitwindow,@IDCloseWindow,&mysub
'IF @MESSAGE = @IDCLOSEWINDOW
'Closewindow #<window>@Hitwindow
'ENDIF
RETURN 0
ENDSUB

LarryMc

what happens when you execute your code as it is stated above?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Hi Larry
Hmmm..
Heapend this...
Simply elink.exe crush.
It looks that callback sub adress cannot be founded .
I never try this before, i mean never try create dll .
Must be possible (i think) but in different way .
I forget option with !....maybe.
As i say if you have any idea what to use?

LarryMc

Aurel
I just noticed your
export MyFuncshould be
export MySub
and
sub MySub
might need to be
sub MySub(),int

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Oh sorry...
Yes i post wrong code but same thing when i fix this. :-\

LarryMc

Can you post the ode you are using to test this?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Here is:
SUB Mywindow(hWnd:window,hwndX:int,hwndY:int,hwndW:int,hwndH:int,wStyle:int,wParent:int,wCap:string),INT
IF wstyle=0
wStyle=@minbox
ENDIF
RETURN OPENWINDOW hWnd,hwndX,hwndY,hwndW,hwndH,wStyle,wParent,"Simple Draw",&MyFunc
ENDSUB

SUB MyFunc(),INT
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
Closewindow #<window>@Hitwindow
ENDSELECT
RETURN 0
ENDSUB


Hmm ..error say :
Error: Cannot export a reference to another export: MyWindow
Error(s) in linking C:\Program Files\EBDev\projects\DLLWindow.dll

LarryMc

You still didn't show me all your code but it doesn't matter.
The following code works for me:
The following dll source file compiles without error and creates a_dll.dll
export Mywindow
export MyFunc

SUB Mywindow(hWnd:window,hwndX:int,hwndY:int,hwndW:int,hwndH:int,wStyle:int,wParent:int,wCap:string),INT
IF wstyle=0
wStyle=@minbox
ENDIF
RETURN OPENWINDOW hWnd,hwndX,hwndY,hwndW,hwndH,wStyle,wParent,wCap,&MyFunc
ENDSUB

SUB MyFunc(),INT
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
Closewindow #<window>@Hitwindow
ENDSELECT
RETURN 0
ENDSUB

I then used the IDE Tools/Create Import Library to create a_dll.lib (which must exist in order to write a program that uses the dll.)

I then created the necessary inc file :
$use "a_dll.lib"
declare extern Mywindow(hWnd:window,hwndX:int,hwndY:int,hwndW:int,hwndH:int,wStyle:int,wParent:int,wCap:string),INT
declare extern MyFunc(),INT


I then created the following test program in order to test the dll:
$include "aurel1.inc"

window w1
Mywindow(w1,20,20,400,400,@MINBOX|@MAXBOX|@SIZE,0,"Works for me Aurel")
centerwindow w1
WAITUNTIL w1 = 0

END

Note: the dll has to be in the same folder as the exe file.

Everything is attached in the zip.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

QuoteYou still didn't show me all your code but it doesn't matter.
I really don't understand. ???
I show you this two function which i try to compile into dll.
And i really not know what i mess ::)
Something is strange?
Thank you  ;)
I will try now..

aurelCB

Oh my i see now what i mess up. ::)
I have two sources in first i do this :
SUB MyFunc(winMSG:INT),INT
winMSG= @MESSAGE
SELECT winMSG
CASE @IDCLOSEWINDOW
Closewindow #<window>@Hitwindow
ENDSELECT
RETURN winMSG
ENDSUB


because of this refuse to compile without error.
sorry Larry...ufff :-\

So if i want use window from this new dll i must also create .lib file to.
Is possible use functions from dll without .lib file ?
For example with LoadLibrary api function ?
Thanks... ;)
I just ask

LarryMc

QuoteIs possible use functions from dll without .lib file ?
For example with LoadLibrary api function ?
Yes, it can be done.  Searching for LoadLibrary in the forums will show several places where that has been done.

In my opinion using LoadLibrary just over-complicates something that is simple and straight forward by creating a lib file.
Either way you have to provide the user with the dll and you are the only one that needs the lib file.
There is a section in the help file about using/creating dlls and their linking-libs.

If you choose to go with the LoadLibrary method I probably won't be able to help you if you run into any problems.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Hi...
After long time i tried to use dll creted in IWB(EB)...
in another programming language ( o2).
And widow is created but i simply cannot hold wndow visible?
In another words it looks that function MyFunc()
not return properly DefWindowProc to opened window.
If i use while/wend loop like this :

while 1
MyFunc()
wend

procesor just jump to 100% and window not respond..
any ideas...

LarryMc

Can't help unless you show me code in MyFunc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Hi Larry... :)
Code is same as yours:
SUB MyFunc(),INT
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
Closewindow #<window>@Hitwindow
ENDSELECT
RETURN 0
ENDSUB


And i really can't figured why this functions is not visible by Mywindow function
or maybe MyFunc must return
DefWindowproc   by default...
I hope that you have now better scope on this tip... ;)

By the way dll produced must work from any other compiler ,right?
tricky thing... :-\

LarryMc

I'm assuming you have MyFunc inside the DLL. Is that correct?

Show me the code where you are opening the window.
Is that code also in the DLL?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

OK, I just went back and read this entire thread.
You are coming back to the code you were working on 10 months ago.

I'm assuming this
while 1
MyFunc()
wend

is code in that other programming language.
That tight loop is what is running the CPU to 100% which makes everything else stop.

You are making the assumption that repeatedly calling the handler routine in this manner somehow magically loads the IW @message constant with the correct value and loads the @wparm and @lparm constants with the correct values.
Or, more importantly that the IWBasic constant @Hitwindow is being loaded with the correct window hwnd value.

These are the things for you to remember if you're wanting to use an IWB dll with a language other than IWB (that right there says I shouldn't be helping you  ;D ;D
1. the dll can only contain IWB commands and/or statically linked apis, etc.
2. the program in the other language can not use any IWB commands; it can only call exported functions in the dll.
3. all IWB windows require that you use WAITUNTIL or WAIT somewhere in a loop so that the windows messages can be processed.

So, there are some questions I would need you to answer in order for me to determine what the code would need to look like.
These are questions about the language you are going to be using to call the dll functions.
Can it handle User Define Types? - the WINDOW variable is a UDT
Can vaiables be passed by reference as well as by value?
Can subroutine addresses be passed with pointers? - like &myhandler
Are you wanting to be able to open one window or multiple windows?
If multiple windows, will they all use the same message handler?
Answer these(I'll probalby have more) and I'll see if I can put some more working code together for you.

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Hi Larry..
QuoteCan it handle User Define Types? - the WINDOW variable is a UDT
Can vaiables be passed by reference as well as by value?
Can subroutine addresses be passed with pointers? - like &myhandler
Are you wanting to be able to open one window or multiple windows?
If multiple windows, will they all use the same message handler?

The language is oxygen basic and can all this things and even more because is on
more low level than IWB -( i can use macro commands on any level)
pointers can have any level of indirection....etc
BUT GUI part is problematic.( nothing built in..)
Only reason why i use OB is a speed.
Yes you right i have made stupid thing with while loop... ::)
and i completely forget to use WAITUNTIL which is infact message loop .
For start i need to open one window that i can see how work. ;)

Thanks... ;)

LarryMc

Okay, that makes me think you want a general purpose interface.

Also, that would make me think you would be better off with a static lib as opposed to a dll

I downloaded OB to get the help file and examples.  The first example was for creating a child window.
It looked a lot like  the source code for IWBasic where it creates a window.

If you like OB for speed then you would be going in the wrong direction by adding the loading of a 3rd party dll and then calling high level routines which in turn call the same apis that you can call directly in OB.

I don't think I want to try to learn enough about OB in order to figure out what all it would take to make a clean userfriendly interface between IWB and OB.  IWB has a lot of things happening in the background that saves you a lot of extra coding.

I'm sure that what you are thinking of doing is indeed possible.  I just don't know how long it will take you to work out all the details.

Your problem right now is not whether or not a dll created in IWB will work with OB.  It will.
Your problem is getting the message handling and all the supporting functions coded properly so the dll is functional.

If you choose to persue it I suggest you do your development work totally in IWB, setting up dll functions(wrappers) to call the required support functions.  After all that then you can do the conversion of the front end over to OB.

So start with straightening out your dll message handler and idleloop.
Good Luck! (Even though I wish you were doing all your programming in IWB. ;))
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Larry
Everybody ( or most of them) know that there is no compiler like is IWB ,which
offer such a easy to use GUI aproach ,right?
And that is a one main advantage of IWB.
With IWB you get by default doublebuffered window with full graphics capabilities
which you cannot found in any other compiler and belive me i have try most of them.
So that's why i like IWB . :)

LarryMc

You know I love IWB.
But my old head has trouble trying to help people with a CBasic problem and its code is real close to IWB.

My loyality is with IWB.  If you post code where you need help directly with the dll IWB code I will help you anyway I can.
But I've got too much IWB work to do to get into OB at all, especially since it is sort of a competitor of IWB.

Hope you understand.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

QuoteBut my old head has trouble trying to help people with a CBasic problem and its code is real close to IWB
This is not possible... ;D
For me using CBasic is like riding bike..

Yes i understand your point about OB and don't worry about that . ;)
Thanks a lot... :)