Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - backspace

#31
Perhaps change the name to something else like mytest-dll. For some reason if I make a name with a hyphen, it builds the dll, an exe and the wrapper gbas file. Only if i use a hyphen in the name. No idea why.
Perhaps the name drivers.dll may be confusing something somewhere ?  Just a thought.
#33
Hi, I'm back to ask another silly question.

As I am looking at using GLBasic for some time to come, I need to know what version of the GCC compiler is used in Version 11.261 of GLBasic.
In Version 10.283 of GLBasic the GCC compiler is version 3.4.5
Why I need to know this is to make sure the the MingW (static) libraries, not dlls, I build are compatible with GLBasic in the future. This is only for Windows, the rest of the OS's are of no concern to me.

So if anyone can find the time, I would really appreciate some feedback on this.
In order to find the GCC version, one needs to open a command window, and then in the GLBasic\Compiler\platform\Win32\Bin folder run the following command:  gcc -dumpversion

Thanks in advance.
#34
@ Hemlos: It may seem like a silly question, but did you, after selecting the Win32-dll in the project,  compile the project using Menu: Compiler -> Multi Platform, then select Win32-dll -> Ok? It took me a while to figure out that standard compile does not generate a dll.
Hope you don't mind me asking.
#35
Hi again,
This time I have success. I looked into this wrapper thing, and this is the key to being able to call a dll made in GLBasic. It works and I am elated.
I can't thank you guys enough for your input, this is really totally awesome, and I will be able to build on from here.

Just to share what I have done, so that others may benefit from my effort, and the efforts of all the dll boffs that have posted their stuff on this forum, for people like me to learn from.

The dll source code. This is a project on it's own, and the resulting .dll must be copied into the calling .exe projects ".app" folder.

Code (glbasic) Select

FUNCTION addem#: number1#, number2#
   LOCAL result#
   result# = number1# + number2#
   RETURN result#
ENDFUNCTION

EXPORT addem


The wrapper source code and the actual program that uses it. It is as Hemlos mentioned, this has to be included in the same project as the calling exe in order for it to work.

Wrapper source

Code (glbasic) Select
TYPE GLBDLLWRAPPER

INLINE
   DECLARE_C_ALIAS(addit, "littledll.dll", "addem", (float, float), float);
ENDINLINE

FUNCTION addem#: num1#, num2#
LOCAL res#
INLINE
if(addit){
PRINT ("DLL FOUND", 20,60);
res = addit(num1, num2);
}else{
PRINT ("DLL NOT FOUND", 20,60);
}
ENDINLINE
RETURN res#
ENDFUNCTION

ENDTYPE


Calling program source code

Code (glbasic) Select
GLOBAL num1#, num2#, res#
GLOBAL mydll AS GLBDLLWRAPPER

num1# = 123.45
num2# = 234.21
res# = 101.01

res# = mydll.addem(num1#, num2#)

PRINT res#, 20,80
SHOWSCREEN
MOUSEWAIT


I had a lot of reading to do to see how others made their wrappers, and it seems that to embed it into a TYPE is the easiest and best way to go, That's how they seem to do it. And it works perfectly. With the wrapper, the compiled exe can now see the dll, and load it at runtime as is should. And the dll is written in GLBasic, which is what i was after all the time. And it works.

Thanks again for all your help guys. You are the Bomb.

The working exe and dll, as well as their projects are attached to show that it really does work

PS: Edited some typos. :D

[attachment deleted by admin]
#36
I'm using IDE Version: 10.283
The two sources I posted files come from two different projects. The dll file is compiled as a dll, the exe is a different project compiled as a Windows executable. The exe and the dll are created in their own ".app" folder, under the project folder.

I''ve attached the dll and exe in a zip file.

Edit: I don't know about wrappers, but one should be able to test the "calling" program as a "stand-alone.exe". The .dll was copied into the same folder as the .exe so that it could be found without using a path. The idea of using a dll is to not link anything to the calling program. This "linking" to the dll functions happens at runtime. I have no problem calling a little dll compiled in "c", from GLBasic. Maybe I need some "wrapper" when doing the calling to a GLB dll. I'm new to this in GLB, so really have no clue.



[attachment deleted by admin]
#37
To compile a dll is pretty simple, so I've learned after about 2 days of reading about dlls in the forum and some trial and error. By setting the Project->Options: Platform configuration to Win32-dll and then Compiler->Build multiplatform: Win32-dll. I get a dll with no problem. I thought that my problems were solved.

The problem happens when trying to call the dll from GLBasic. The exe test does not seem to see the dll, no matter what DECLARE format I try. I tried making a small c dll, and that seems to work great.

The GLB DLL code. I tried with both EXPORT addem, and EXPORT addem#, and they both compile fine.

Code (glbasic) Select

FUNCTION addem#: number1#, number2#
   LOCAL result#
   result# = number1# + number2#
   RETURN result#
ENDFUNCTION

EXPORT addem


The GLBasic code to test the dll. With all 4 DECLARE options. They all seem to not see the dll at all, no matter which I use

Code (glbasic) Select

GLOBAL num1#, num2#, res#


INLINE
   //DECLARE(addem, "littledll.dll", (float, float), float);
   //DECLARE_C(addem, "littledll.dll", (float, float), float);
   //DECLARE_ALIAS(addit, "littledll.dll", "addem",  (float, float), float);
   DECLARE_C_ALIAS(addit, "littledll.dll", "addem",  (float, float), float);

ENDINLINE


num1# = 123.45
num2# = 234.21
res# = 101.01

INLINE
    PRINT(res,20,0);
//if(addem){  //without alias
if(addit){    //with alias
    PRINT ("FOUND DLL", 20,20);
//res = addem(num1,num2);  //without alias
res = addit(num1,num2);    //with alias
}else{
    PRINT ("DLL NOT FOUND !!", 20,20);
}
ENDINLINE

PRINT res#, 20,80
SHOWSCREEN
MOUSEWAIT


I sincerely hope that someone knows how to make this work. I don't mind making c dlls, but I'd love to allow the kids to make their own, because it is so easy in GLBasic. Ok the call is a bit more complex, but it should easy to work from an example template.

Thanks for your interest.
#38
Yes, I've found that INLINE does actually work very well. My objective however is to get a dll that is written in GLBasic to actually work.
The idea behind the GLBasic dll is that I need to put together a few computer lessons for later this year, for a group of bright school kids.
Basic is easier to learn than c++, so I've opted to go the GLBasic route. I hope it all works out.
#39
There are a few items that I need to digest, such as being able to DIM the size of an array inside a TYPE. I did not even know this was possible. The AS keyword certainly has many uses. I discovered that I did not need BYREF for arrays, since they were aut0matically passed by reference anyway. A small reference in the help file, and then a look at the generated c++ project code.
I'm used to pointers, so am in the habit of 'enforcing' bounds, but the extra parameter is a safe way to do it. thanks.
This forum rocks. Thanks again for all the help, I'd still be scratching my head without it.   
#40
In the IDE. Menu: Web->Internet Update
I had the same problem, and found a reference somewhere in the forum to this answer. The update fixes this problem.
#41
Aha, I found references to "BY REFERENCE" key words from other BASIC languages, after doing a google search. I am assuming that this is what you mean?
Keep in mind that I am pretty new to GLBasic, and the BASIC language in general. My c++ is OK. So you have to bear with me, if I ask what may be very stupid questions.
#42
Hi again, another question I need help with.

I've written a simple dll in GLBasic, and it works great. I can pass it a float, and get a changed float back

Code (glbasic) Select
FUNCTION func1#: param1#
   LOCAL x#
   x# = param1# + 5
   return x#
ENDFUNCTION

EXPORT func1


But my question has to do with using an array of float as a parameter.

How would I pass the array of float as a parameter, and be able to change the array contents inside the dll, and then get the changed values back into the calling GLB program?

A "do it yourself" answer is really of no use to anyone, and is actually very insulting.
http://www.glbasic.com/forum/index.php?topic=8831.msg75123#msg75123

Since I don't know how this is done, that is why I am asking.
#43
Quote from: mentalthink on 2012-Dec-29
Hi bakcSpace I don't see to yet this library... I think very Usefully, for make some Editor or something for Paint...
Thanks a lot...!!!

It's the source code in the first post.
If you make for example a project with 2 files. Paste the source into the first file. but delete the function named "test". Also delete the call to the function.
In the second file paste only the function name "test". Add a call to the function.
The "test" function is an example of how to use the first file, which is the "library". Name it anything you wish.
Hope this helps.

I actually want to make a paint program, but I still have a lot to learn. Maybe one day I will. :)
#44
I was not familiar with the "AS" keyword. Now I know. lol
Noobs have to start somewhere, and they will "try it themself" when they have learned how !!!
Thank you.
#45
Is it possible to pass a "type" variable as a parameter to a function?