|
Post by scalion on Nov 24, 2021 12:30:04 GMT 1
Hi all, I have a problem, i compile a simple DLL with Dev CPP. But i can't use it in GFA-Basic32
i have this message :
I tested with "rundll32 addition2.dll,HelloWorld" my dll and that work fine.
Here my GFA CODE :
ChDir App.Path Message "test dll " & Iif(Exist("addition2.dll"), "present", "not present") Declare LIB "addition2.dll" Declare Sub Helloworld () Helloworld() //<-error occur
Here my DLL :
Source Dev C++ (it's a sample example code, a bit modified) :
dllmain.c :
/* Replace "dll.h" with the name of your header */ #include "dll.h" #include <windows.h>
DLLIMPORT void HelloWorld() { MessageBox(0,"Hello World from DLL!\n","Hi",MB_ICONINFORMATION); }
DLLIMPORT int additionner(int a, int b) { return a + b; }
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) { switch(fdwReason) { case DLL_PROCESS_ATTACH: { break; } case DLL_PROCESS_DETACH: { break; } case DLL_THREAD_ATTACH: { break; } case DLL_THREAD_DETACH: { break; } } /* Return TRUE on success, FALSE on failure */ return TRUE; }
dll.h :
#ifndef _DLL_H_ #define _DLL_H_
#if BUILDING_DLL #define DLLIMPORT __declspec(dllexport) #else #define DLLIMPORT __declspec(dllimport) #endif
#define EXPORTED __declspec(dllexport) __stdcall
DLLIMPORT void HelloWorld(); DLLIMPORT int additionner(int a, int b);
#endif
All Ideas are welcome !
|
|
|
Post by rogercabo on Nov 24, 2021 19:13:50 GMT 1
* Test your compiled dll in VisualBasic 6.0 at first. If it runs well, then it must run in GFA as well. * From what I know a GUI in a dll does not work in a caller program. I use a lot of dll's from any company and never see a GUI coming up in any dll.
|
|
|
Post by scalion on Nov 24, 2021 20:40:29 GMT 1
* Test your compiled dll in VisualBasic 6.0 at first. If it runs well, then it must run in GFA as well. * From what I know a GUI in a dll does not work in a caller program. I use a lot of dll's from any company and never see a GUI coming up in any dll. Hi roger,
Thank you verymuch, I had not thought of testing with VB, I will do this and come back.
|
|
|
Post by rogercabo on Mar 13, 2022 22:37:25 GMT 1
Should Hamstra wrote a special declare for some 32bit .dll types. Not every dll 32bit has the same header. I never know this before. The basic declare in gfa32 does not work with every 32bit dll. But it's possible anyhow.
|
|
|
Post by (X) on Aug 25, 2022 2:52:48 GMT 1
I was looking into compiling a DLL in C++
Copying it to GFA Basic directory and trying to use it like a DLL provides API functions.
To my utter surprise, I got this to work!
This guy explains what to do...
Here is the MS documentation...
I am going to try out more meaningful code but this seems to work. I named my DLL "Dll_Multi_Win", which doesn't make much sense, but, you can name yours as you wish.
$Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
Declare LIB "Dll_Multi_Win"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' fibonacci_init(const unsigned long long a,const unsigned long long b) ' Declare Function fibonacci_init (a%, b%) Declare Function fibonacci_next () As Bool Declare Function fibonacci_current () As Long Declare Function fibonacci_index () As Long
OpenW 1
Debug "Test Fibonacci Sequence"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Initialize a Fibonacci relation sequence. ' fibonacci_init(1, 1)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Write out the sequence values until overflow. ' Do Trace fibonacci_index() Trace fibonacci_current() Trace fibonacci_next() Loop Until (fibonacci_next())
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Report count of values written before overflow. ' Debug Str(fibonacci_index() + 1) & " Fibonacci sequence values fit in an unsigned 64-bit integer."
Do Sleep Until Me Is Nothing This is the Debug Window Output... There is something wrong with this output - I expected a list of increasing numbers - but at least there are no errors. I am going to work out a better example.
|
|
|
Post by (X) on Aug 26, 2022 2:25:19 GMT 1
Another video with good explanations...
Within this video we see how to create and object that can be used to call a function with the syntax:
<object_name>.<method_name>
I was thinking that if we create a "Color_Space" object, then, we could call a method to return specific property values.
For example is we assign a color:
CS.C = RGB(255,255,255)
We could have an object method that directly return the R, G, B, H, S or L property values.
Print CS.R // Should print 255
' And if there is a method to calculate and return the hue, then:
Print CS.H // Should return the hue
|
|
|
Post by rogercabo on Aug 27, 2022 16:20:11 GMT 1
I would love to write a DLL in c#. C# code respond faster then c++. Unity3D decide to use c# instead of C++ and they show c# is overall faster in the most cases. And I must say c++ is so far away from c# I now so well 
|
|
|
Post by (X) on Aug 27, 2022 16:25:39 GMT 1
I would love to write a DLL in c#.
Are you saying you can not write a DLL in C# or can not get one to work with GB32?
|
|
|
Post by dragonjim on Aug 27, 2022 16:28:53 GMT 1
Just out of interest, you can do something like this already...
Type ColourComponents B As Byte G As Byte R As Byte EndType Type Colour Union C As Int32 CC As ColourComponents EndType Local c As Colour c.C = RGB(120, 200, 255) Trace c.CC.R Trace c.CC.G Trace c.CC.B Debug.Show
Not sure how you work out a colour's Hue, Saturation, etc. so can't help there.
|
|
|
Post by (X) on Aug 27, 2022 16:49:41 GMT 1
My goal is to create an easily imported / declared Color_Space_Object.DLL that will return calculated values automatically without having to call a function explicitly in the main code. If we assign a color to a color space object typed variable: cso...
// // Dim variablename As [New] { objectclass | Object } // Dim cso as New Color_Space_Object
cso.rgb = RGB(1,1,1)
I would like the DLL based object code to return the Hue using a "built-in" method or function: Print cso.Hue
Instead of having to use a function: Print Hue(cso.rgb) The "Hue" function or "method" would be "built-in" to the Color_Space_Object.DLL Other methods would be for : Luminance: Lum, Saturation: Sat and many more. All these would be directly accessible in code: Print cso.Sat Print cso.Lum I just have not got around to trying this out yet. It just seems like an interesting thing to do. I am no expert in C++ and would be just as happy to produce a DLL in any other way. If it's easier and faster, so much the better!
|
|
|
Post by (X) on Aug 27, 2022 17:19:09 GMT 1
Not sure how you work out a colour's Hue, Saturation, etc. so can't help there. I got that covered.
|
|
|
Post by rogercabo on Aug 27, 2022 19:33:39 GMT 1
I would love to write a DLL in c#.
Are you saying you can not write a DLL in C# or can not get one to work with GB32?
I never tried to wrote a C# DLL in VS. And I must admit.. since we had libraries in GB32, is there any real advantage or any technical reason to build an DLL?
|
|
|
Post by (X) on Aug 27, 2022 19:41:28 GMT 1
I saw an opportunity to create Object behaviour as in OOP using C++ to produce a DLL. One advantage of Objects is that in the Object's Class definition, an attribute can be a variable or method.
So, can we create OOP Objects or equivalent in GFA?
How could we do this in GFA:
If we define a UDT...
Type T_Area -int w, h, area EndType Is there a way to get GFA to call a function: Function Area_Calc(w%, h%) as Int Return w * h EndFunc If we just try to use: Dim A as T_Area Print A.area // How can A.area automatically calculate the area using the Area_Calc() function? I don't know if GFA can do that automatically within an LG32. I suppose some form of polling or equivalent of "UponChange of .w% or .h% Update .area%" would have the calculation updated and ready to go.
I am really wondering if in GFA we can call a method by specifying an <object>.<attribute> of our own design like we obviously can use for example: frm1.width?
For me, it has become more of a matter of curiosity than anything that would necessarily even be very useful.
|
|
|
Post by dragonjim on Aug 28, 2022 10:41:24 GMT 1
In a nutshell, GB32 does not provide the facility to create user-defined Object Class structures, although it obviously has support for the in-built OCX objects and declared external objects defined in DLLs.
In theory, it would not be hard to add (create new UDT types which contain function addresses and use the PasCall function code to return the result); in practice, it would mean rewriting large sections of the IDE and Compiler.
You could add a special function (Class()?) to do the same thing from a LG32 library (in theory) and call it from within a GB32 program, but this would not give you the simplicity of instruction that you are after.
Below is a very quickly thrown together example of this:
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
Global col As Colour ColourObjectDefine(col) col.C = RGB(20, 120, 85) Trace Class(col.R) Class(col.R, 60) Trace Class(col.R)
// Library Files
Type Colour C As Int32 R As Large G As Large B As Large EndType
Function ColourObjectDefine(ByRef c As Colour) Local vc As Large = Shl8(V:c, 32) c.R = ProcAddr(ColRed) + vc c.G = ProcAddr(ColGreen) + vc c.B = ProcAddr(ColBlue) + vc EndFunction Function Class(addr As Large, ParamArray p()) Local paddr% = LoLarge(addr) Local pa As Variant = p If paddr% = ProcAddr(ColRed) : Return ColRed(addr, pa) ElseIf paddr% = ProcAddr(ColGreen) : Return ColGreen(addr, pa) ElseIf paddr% = ProcAddr(ColBlue) : Return ColBlue(addr, pa) EndIf EndFunction Function ColRed(addr As Large, pa As Variant) Local c As Colour, udtaddr% = HiLarge(addr) : BMove udtaddr%, V:c.C, SizeOf(Colour) If UBound(pa) = -1 : Return GetRValue(c.C) ElseIf UBound(pa) = 0 If IsNumeric(pa(0)) : c.C = RGB(pa(0), GetGValue(c.C), GetBValue(c.C)) : BMove V:c, udtaddr%, SizeOf(Colour) : Return c.C Else : Trace pa(0) : Message "Parameter passed non numeric" : End EndIf Else : Message "Too many paramaters passed" : End EndIf EndFunction Function ColGreen(addr As Large, pa As Variant) Local c As Colour, udtaddr% = HiLarge(addr) : BMove udtaddr%, V:c.C, SizeOf(Colour) If UBound(pa) = -1 : Return GetGValue(c.C) ElseIf UBound(pa) = 0 If IsNumeric(pa(0)) : c.C = RGB(GetRValue(c.C), pa(0), GetBValue(c.C)) : BMove V:c, udtaddr%, SizeOf(Colour) : Return c.C Else : Trace pa(0) : Message "Parameter passed non numeric" : End EndIf Else : Message "Too many paramaters passed" : End EndIf EndFunction Function ColBlue(addr As Large, pa As Variant) Local c As Colour, udtaddr% = HiLarge(addr) : BMove udtaddr%, V:c.C, SizeOf(Colour) If UBound(pa) = -1 : Return GetBValue(c.C) ElseIf UBound(pa) = 0 If IsNumeric(pa(0)) : c.C = RGB(GetRValue(c.C), GetGValue(c.C), pa(0)) : BMove V:c, udtaddr%, SizeOf(Colour) : Return c.C Else : Trace pa(0) : Message "Parameter passed non numeric" : End EndIf Else : Message "Too many paramaters passed" : End EndIf EndFunction
|
|
|
Post by (X) on Aug 28, 2022 22:31:19 GMT 1
I've just watched 10's of videos about all of this.
I still don't have a working demo where GFA can declare a Class or Object stored in a DLL.
Am I totally missing the point and forgetting that I should really be creating an OCX?
|
|
|
Post by dragonjim on Aug 29, 2022 8:36:39 GMT 1
GFA can create class objects through the CreateObject command.
Check out the Automation page of the help file; as well as listing GFA's limited support, there is also a link to a very interesting article by Sjouke on the subject.
|
|
|
Post by (X) on Aug 29, 2022 13:43:28 GMT 1
I have not finished reading Sjouke's article, but, by the looks of it, it doesn't look good for 3rd party COM Object / OLE / ActiveX... I was at it until 03:30 this morning, sniffing around GetObject() and CreateObject() permutations, then I stumbled upon ATL* (Active Template Library OCX/ActiveX creation tool? in VSC++) which got me real interested.
I feel I am still missing quite a few key pieces of the puzzle.
* Interesting 2011 interview of the creator of ATL... "[06:34] Charles interviews Jim Springfield (whiteboarding included)"
ATL Primer ...
|
|
|
Post by (X) on Aug 29, 2022 17:02:51 GMT 1
Sjouke says:
Did Sjouke ever expand on this? I went through the various posts on his blog searching for OOP, OCX, Object..., but, I didn't find any follow-up.
This demo does seem to work as explained. We must be close to an implementation.
// IUnknownBlog.g32 17.07.2011 Debug.Show
// Our COM object: an implementation of IUnknown GUID IID_IUnknownImpl = 9578fdab-97cb-4322-99e4-699abd26be1d Type IUnknownImpl lpVtbl As Pointer IUnknownImplVtbl RefCount As Int EndType
// VTABLE (an array of function pointers) Type IUnknownImplVtbl QueryInterface As Long AddRef As Long Release As Long EndType Static IUnknownImplVtbl As IUnknownImplVtbl With IUnknownImplVtbl .QueryInterface = ProcAddr(IUnknownImplVtbl_QueryInterface) .AddRef = ProcAddr(IUnknownImplVtbl_AddRef) .Release = ProcAddr(IUnknownImplVtbl_Release) EndWith
// First create a heap allocated instance // of our implementation of IUnknownImpl Dim pIUnk As Pointer IUnknownImpl Pointer pIUnk = mAlloc(SizeOf(IUnknownImpl)) Pointer pIUnk.lpVtbl = *IUnknownImplVtbl pIUnk.RefCount = 1
Dim obIUnk As Object {V:obIUnk} = V:pIUnk Trace obIUnk
Dim o As Object // assign to other Set o = obIUnk // AddRef() call // two calls to Release /*** END ***/
GUID IID_IUnknown = 00000000-0000-0000-c000-000000000046 Global Const E_NOTIMPL = 0x80004001 Global Const E_NOINTERFACE = 0x80004002 Declare Function IsEqualGUID Lib "ole32" (ByVal prguid1 As Long, ByVal prguid2 As Long) As Bool
Function IUnknownImplVtbl_QueryInterface( _ ByRef this As IUnknownImpl, riid%, ppv%) As Long Naked Trace Hex(*this) {ppv} = Null If IsEqualGUID(riid, IID_IUnknownImpl) || _ IsEqualGUID(riid, IID_IUnknown) {ppv} = *this IUnknownImplVtbl_AddRef(this) Return S_OK EndIf Return E_NOINTERFACE EndFunc
Function IUnknownImplVtbl_AddRef(ByRef this As IUnknownImpl) As Long Naked Trace Hex(*this) this.RefCount++ Return this.RefCount EndFunc
Function IUnknownImplVtbl_Release(ByRef this As IUnknownImpl) As Long Naked Trace Hex(*this) this.RefCount-- If this.RefCount == 0 Then ~mFree(*this) Return this.RefCount EndFunc
|
|
|
Post by dragonjim on Aug 31, 2022 10:40:19 GMT 1
From what I understand of COM objects, they are identified by unique ID numbers (three if I remember correctly) which are then used by GFA to link to it and create the object.
I can not remember if Sjouke published any further articles on COM objects but I do remember that he was planning to transfer the OCX controls to COMs many years back but was unable to complete this. Whether that was due to technical issues with GFA or just the complexity of creating the objects I do not know - I guess the latter as GFA works with most of the COM objects of which I am aware.
|
|
|
Post by (X) on Aug 31, 2022 23:37:32 GMT 1
I have made several unsuccessful attempts to produce a COM object (DLL) using VSC++ via ATL* that can be imported by GFA via CreateObject() or GetObject().
If I do succeed, this should open the door to many specialized controls that could easily enhance any GFA program. * www.techtarget.com/whatis/definition/Active-Template-Library-ATL
|
|
|
Post by (X) on Sept 19, 2022 14:13:33 GMT 1
I have succeeded in genrerating a DLL containing a Class/Object that can be 'imported' into GB32 via CreateObject(<ProgID>) using C++ which took 2 weeks to get up to speed and once I got the hang of it, 3 days in C#. I found it vastly more complicated in C++, but it still works.
I imagine I should produce a video/tutorial of this to explain all the steps and pitfalls to avoid.
|
|
|
Post by rogercabo on Sept 26, 2022 11:00:39 GMT 1
I would love to write a DLL in c#.
Are you saying you can not write a DLL in C# or can not get one to work with GB32?
I don't know how to setup a VS2019 Project to build a dll in C# currently. Perhaps I can build a dll is able to transfer files via SFTP to a web server. And receive files as well. But if this require to implement all protocols from SFTP that's too massive. Send and receive files (secure) to a server is so important these days, also for GFABasic32 to keep it alive.
Perhaps your nice project "Declare a DLL compiled with Dev C#" can help here. If GB32 is able to call a c# compiled DLL contain Net.X, and the ability to use a proper SFTP lib, then I would give it a try.
On the other hand a web server and some PHP acknowledge is required to handle the server side. The PHP code must check some security properties of the file and handle where to move the file on the web server. Here in this PHP case I also seed some help. For sure I would post a complete "how to transfer files for the gb32 community".
Then it's also possible to use a mobil phone to access the data have send with GB32 to the web server.
|
|
|
Post by (X) on Sept 26, 2022 23:02:56 GMT 1
I usually get Instant notification when someone adds a post, but, somehow I missed your post until now.
Quick question: Why not use Google Drive?
|
|
|
Post by rogercabo on Sept 27, 2022 23:21:59 GMT 1
I usually get Instant notification when someone adds a post, but, somehow I missed your post until now. Quick question: Why not use Google Drive? Transfer files to a server is for some of my current project tools I'm working on. It's a schedule working planer. It's not for myself only. And I can not expect that other ppl use Dropbox. So I need my own server to transfer files.
The www.chilkatsoft.com/ tool is able to do with Pure Basic 32. But Chilkat cost about 300$ a year. That's too expensive. And I don't need such a complex SDK like Chilkat. There is also another www.sftp.net/clients#windows site provide tons of formats and software. This is really hard to understand what is a easiest solution in this case. I only need to transfer files in a most secure way to a web server and back.
|
|
|
Post by (X) on Sept 28, 2022 1:28:08 GMT 1
I am really new to all of this. Did you evaluate WinSCP? WinSCP is an open source free SFTP client, FTP client, WebDAV client, S3 client and SCP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.
I looked up SFTP in the PowerBasic Forum and the only example I found refered to SocketTools that is free to test but is not free.
It seems, if one can develop a good SFTP DLL people will gladly pay for it.
|
|
|
Post by (X) on Sept 28, 2022 15:44:21 GMT 1
Apparently windows comes with a program called sftp that lets you perform sftp operations including batch files.
How to use SFTP Commands to Copy Files to/from a Server
Setting up an SFTP Server on Windows (Server) with OpenSSH (using Microsoft's port of OpenSSH)
Attachments:
|
|
|
Post by rogercabo on Sept 30, 2022 16:38:59 GMT 1
Apparently windows comes with a program called sftp that lets you perform sftp operations including batch files.
How to use SFTP Commands to Copy Files to/from a Server
Setting up an SFTP Server on Windows (Server) with OpenSSH (using Microsoft's port of OpenSSH)
Thank you.. Unfortunately I need a solution inside a dll to cover path, filenames, and server connections, etc. The example : How to use SFTP Commands to Copy Files to/from a ServerIs not secure because you have to pass all server info in plain text into a batch or system/cmd command. In the second video , its required to install a openSSH api/dll on the user machine. This is not a good idea because of security concerns every user will run into. I would like to have something like this:
Declare sftp32.dll SendFile(filename, path, "KDODI37HK" /*crypted info for the server where to copy the file on server */, Timer) // Async
Declare sftp32.dll ReceiveFile(filename, path, "K7894537HK" /*crypted info from where the file to get from the server*/, Timer) // Async
One ulgy thing i need: I require to run a loop while sending the file, so I will know if the file is successfully arrived on the server. Question: what happen if the server connection is lost while send of receive files.. TimeOut?
The connection info should coded inside of the dll. I don't want to send it by GFABASIC to the dll.
X if you like to do for some money, tell me what you want to have for. * In the end I need the C# source from the DLL to code some special behaviors for the PHP script on the server. * I can setup a web server where you can try.
------------------------
|
|
|
Post by (X) on Sept 30, 2022 22:10:29 GMT 1
This is getting pretty close to what you want I think:
' Setup session options Dim sessionOptions Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions") With sessionOptions .Protocol = Protocol_Sftp .HostName = "example.com" .UserName = "user" .Password = "mypassword" .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." End With Dim session Set session = WScript.CreateObject("WinSCP.Session") ' Connect session.Open sessionOptions ' Upload files Dim transferOptions Set transferOptions = WScript.CreateObject("WinSCP.TransferOptions") transferOptions.TransferMode = TransferMode_Binary Dim transferResult Set transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions) ' Throw on any error transferResult.Check ' Print results Dim transfer For Each transfer In transferResult.Transfers WScript.Echo "Upload of " & transfer.FileName & " succeeded" Next ' Disconnect, clean up session.Dispose
|
|
|
Post by (X) on Oct 1, 2022 1:48:10 GMT 1
|
|
|
Post by rogercabo on Oct 2, 2022 19:14:24 GMT 1
Thanks for the demos and information! Currently I'm under pressure to review the first test run to the clients. End of the next week I have the time to start some tests to send and receive files to the web server. And i must ask what is required on the server side. With FTP it was possible to change/create/remove directories, and all the file commands we had in windows GFABasic. Not sure what I have to do to coordinate where files are going on the server.
|
|