Module/DLL problem (PChar?)

BlitzMax Forums/BlitzMax Programming/Module/DLL problem (PChar?)

Ghost Dancer(Posted 2010) [#1]
I'm trying to write a wrapper module for a DLL I want to use. This is the first time I've attempted this and have followed various instructions in other posts.

The module builds OK but one of the DLL functions does not return the expected value and the other causes an exception during run-time. I think it might be my datatype declarations in handling PChar - I'm guessing its a string pointer not an actual string? But I'm not sure how to handle this in Max.

The syntax of the DLL functions is as follows:



And my module has the following:



Could someone please point me in the right direction (pun intended) as to how to handle PChar and/or if I am doing anything else wrong. Thanks.


plash(Posted 2010) [#2]
Try $z for PChar (CString).

Do you know if the dll was written in Delphi?
Also, you might be able to figure out the types if there's a C header with the dll.


Ghost Dancer(Posted 2010) [#3]
Thanks for that. How do I pass a string parameter as $z to the function?

Not sure what the DLL is written in, but the main example that came with it is in Delphi so there is a good chance that is what is is written in!
I have no idea how to view the dll header anyway and my knowledge of C is somewhat limited so looking at that would not really help me. If it helps, the DLL can be downloaded from http://www.is-soft.de/pdfanalyzer/prod14.htm


Dreamora(Posted 2010) [#4]
with $z / $w it was meant that you dont use:string in the extern definition but $z / $w actually

for sending it in, just call the function with a string, bm will do the rest of the conversion for you


Floyd(Posted 2010) [#5]
LongInt probably means 32-bit integer.


plash(Posted 2010) [#6]
http://www.delphibasics.co.uk/ByFunction.asp?Main=Types


Ghost Dancer(Posted 2010) [#7]
Thanks Dreamora, that works when calling the function, but how to I set the default value of a parameter to a null string? Using "" gives a compiler error saying it can't convert from string to cstring - I guess some other syntax is required here?

Floyd - yep, you are correct. Thanks.

The GetPDFPageCount function is now working, just need to sort the default cstring values and it will be done :)


plash(Posted 2010) [#8]
I do not think you can put default values inside extern function definitions.


Ghost Dancer(Posted 2010) [#9]
The other default values seem to be OK, its only the $z ones that the compiler is giving an error for


Brucey(Posted 2010) [#10]
I do not think you can put default values inside extern function definitions.

Correct.


Ghost Dancer(Posted 2010) [#11]
Ah OK. I've removed optional params and it now works ok specifying all params. Thanks to you all for your help :)

I have a couple more questions (sorry if these seem stupid questions but I've not delved into making modules before). Since I can't use default values on the params, I thought I'd make a few wrapper functions as most params are not need often. My module now looks like this:



It compiles OK, but I get a runtime exception error when using the functions I have added. Example code:

Import kudos.pdftext

Print pdfGetString("testfile.pdf", 11)

End


Any ideas why these functions do not work?


Also, if I don't explicitly put the End statement in the code the program hangs - not a major problem but just want to make sure I'm not doing something wrong which is causing this and could potentially create other problems.


Ghost Dancer(Posted 2010) [#12]
After testing this further I've been getting a number of problems, which I'm certain is to do with how I've implemented this and not the DLL itself.

After using one of the functions its seems to screw something up. If I do not use the End statement after a call it gives an exception error and the program hangs. In normal mode it prints the string returned from the function but in debug mode it does not.

Print GetPDFText(pdfFile$, OPT_STRING, False, False, "", False, "", True, 11, False, False, 0, 0)


If I make a second call to the function (instead of the End statement) I get the same error, so something must be fundementally wrong with my module that causes this to happen after the function is called.

Any help with this would be greatly appreciated. Thanks


Ghost Dancer(Posted 2010) [#13]
After some searching, I found an alternative way of using the DLL, which not onyl works correctly but is much simpler too :-)

For anyone else wanting to do this, the code is as follows:

Local dll = LoadLibraryW("pdftext.dll")

Global GetPDFPageCount:Int(FileName$z) "win32" = getprocaddress(dll,"GetPDFPageCount")
Global GetPDFText$z(FileName$z, opt:Int, hw:Int, fast:Int, target$z, lspaces:Int, ptitel$z, pos:Int, page:Int, clock:Int, blank:Int, ende:Int, wlist:Int) "win32" = getprocaddress(dll,"GetPDFText")