Compiling errors #2

New to FreeBASIC? Post your questions here.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Compiling errors #2

Post by caseih »

deltarho[1859] wrote:You made a typo with bcrypt2. However, I am still getting ' undefined reference to `BCryptHash' '
Actually no, that's correct. If you read his post he created a new import library, libbcrypt2, so as to not conflict with the original bcrypt import library that shipped with FB
Added: Dear, oh dear. It cannot work for me because you have a new import library and I don't. Isn't getting old wonderful. <Ha, ha>
He did show how he made the import library. And I suppose he probably could post it somewhere too.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

I know that it was not a typo. My 'Added:' effectively wrote off what I had written above.

I should have deleted the post - I have just done so.

I can actually do the import library but I prefer not to mess with them. The declaration employing 'wall to wall' 'As Any Ptr' makes a farce of FB's strict type checking modus operandi. Whilst I would prefer a less strict regime I could not endorse anarchy.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

It is very easy to translate to FB style

C++ declaration:

Code: Select all

NTSTATUS WINAPI BCryptHash(
   BCRYPT_ALG_HANDLE hAlgorithm,
   PUCHAR            pbSecret,
   ULONG             cbSecret,
   PUCHAR            pbInput,
   ULONG             cbInput,
   PUCHAR            pbOutput,
   ULONG             cbOutput
);
FreeBasic declaration:

Code: Select all

DECLARE FUNCTION BCryptHash ( _
   BYVAL hAlgorithm AS BCRYPT_ALG_HANDLE, _
   BYVAL pbSecret AS PUCHAR, _
   BYVAL cbSecret AS ULONG, _
   BYVAL pbInput AS PUCHAR, _
   BYVAL cbInput AS ULONG, _
   BYVAL pbOutput AS PUCHAR, _
   BYVAL cbOutput AS ULONG, _
   ) AS NTSTATUS
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Compiling errors #2

Post by dodicat »

I made wall to wall any ptr as a simplification to get a runner.
(After all, is was sorely due here)
You can include the various .bi files to get the datatypes.

Code: Select all

 
#Include Once "windows.bi"
#Include Once "win/wincrypt.bi"

Extern "Windows-MS"
Declare  Function MyBCryptHash  Lib "bcrypt2" Alias "BCryptHash"( As BCRYPT_ALG_HANDLE, As puchar,As Ulong, As puchar, As Ulong,As puchar, As Ulong ) As NTSTATUS
End Extern

print @MyBCryptHash

sleep 
But all in all this seems a crazy way to go about this when dylibload/dylibsymbol suffices.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

Re: José's last post. Yep, and what I mentioned above - stick to the bi and MSDN data-types like glue, include what bi we have to and then let the compiler get on with.
dodicat wrote:I made wall to wall any ptr as a simplification to get a runner.
Fair enough.
But all in all this seems a crazy way to go about this when dylibload/dylibsymbol suffices.
Makes you wonder why bother with import libraries at all. Dynamically load and stack'em up in an inc file as Private ( José Roca technique ). Call one, it loads and the rest stay where they are and don't get loaded.

What we need, or at least I do, is a really neat wrapper for dylibload/dylibsymbol. I have kicked a few around but they all fell short of neat - closer to a dog's dinner more like.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Compiling errors #2

Post by dodicat »

Not very neat.

Code: Select all



#macro declareM(fname,ftype,libname,libfunctionname)
dim fname as ftype
scope
var L=dylibload(libname)
if L=0 then print "Error in " +#libname:sleep:end
fname=dylibsymbol(L,libfunctionname)
if fname=0 then print "Error in " +#libfunctionname:sleep:end
end scope
#endmacro


DeclareM(mbox,function(as any ptr,as zstring,as zstring,as long,as long,as long) as long,"user32.dll","MessageBoxTimeoutA")
DeclareM(SetBlueBorder,function(As Any Ptr,As zstring Ptr,As zstring Ptr) As Long,"UxTheme.dll","SetWindowTheme")


mbox(0,"You have three seconds","Brief encounter",0,0,3000)

screenres 200,100
setmouse 0,0 'for 64 bit
Dim ThisWindow As Any Ptr
Screencontrol 2, *Cptr(Integer Ptr,@ThisWindow )
SetBlueBorder(ThisWindow," "," ")
print "press any key to end"

sleep
  
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Compiling errors #2

Post by deltarho[1859] »

dodicat wrote:Not very neat.
Actually, I find that very neat. Structurally, I buy into all of that.

It had not occurred to me to use a macro and I had not seen the Preprocessor Stringize (#) before. I don't have sufficient confidence in the language to use Var so tend to steer clear of it.

Our coding styles differ: I tend to use a lot of white space, capitalization, indentation and long names rather than letters.

For what it is worth I ended up with this.

Code: Select all

#Macro DeclareMacro( ProcName, Proc_List, LibName, LibFunctionName )
Dim ProcName As Proc_List
Scope
  Dim As Any Ptr Library = Dylibload( LibName )
  If Library = 0 Then Print "Error loading " + #LibName : Sleep : End
  ProcName = Dylibsymbol( Library, LibFunctionName )
  If ProcName = 0 Then Print "Error finding " + #LibFunctionName : Sleep : End
End Scope
#Endmacro
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

First you need a prototype:

Code: Select all

TYPE <proc name, e.g. pfnxxxproc> AS FUNCTION (or SUB) [CDECL] (<parameters>) AS <return type>
Note: The calling convention is optional. You may need to use CDECL with some C DLLs.

Then get the address of the procedure and cast it:

Code: Select all

DIM pProc AS pfnxxxproc = cast(pfnxxxproc, (GetProcAddress(LoadLibrary("dllname", "procname"))))
Then call the procedure through its function pointer:

Code: Select all

IF pProc THEN <return value> = pProc(<parameters>)
Last edited by Josep Roca on Mar 24, 2018 10:36, edited 1 time in total.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Compiling errors #2

Post by dodicat »

Perhaps
Dim shared ProcName As Proc_List
is more general.
Also, loadlibraryex is more versatile than dylibload (For vb dll's as shown a few weeks ago)
dylibsymbol is compatible with loadlibraryex.
Apart from that, it is probably a rarity to have to update the .dll.a file.
But because the compiler is at a standstill now, it will obviously become more and more out of touch with Windows dll's.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

Except for Windows system libraries, I don't use DyLibLoad because it does not work with unicode.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Compiling errors #2

Post by caseih »

Josep Roca wrote:Except for Windows system libraries, I don't use DyLibLoad because it does not work with unicode.
How so? Are you speaking of the names of the symbols?
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compiling errors #2

Post by Josep Roca »

No. I'm speaking of the names of the DLLs to load.
Post Reply