Purebasic DLL with strings as parameters

BlitzMax Forums/BlitzMax Programming/Purebasic DLL with strings as parameters

byo(Posted 2009) [#1]
Hi, guys.

I guess I'm a little stuck here. I have this DLL I've made, no big deal and it has these functions:

ProcedureDLL comInit()
ProcedureDLL.l comCreate(name.s, progID.s)


I'm trying to make myself a little mod with it (I have .LIB file) so I'm doing it like this:

Module byo.com

Import "mfxCom.lib"

Extern
	Function comInit() "win32"
	Function comCreate:Int(name:String, progId:String) "win32"
End Extern


No matter what I do, I can't make the ComCreate function return anything other than 0. It should return 1 for success and 0 for error. The DLL works in Purebasic and in Visual C++ like this:

comCreate("byo", "Word.Application")


Somehow I think there's something wrong with the strings being passed as parameters? Could you guys see what I'm doing wrong. I'd appreciate very much as this is taking me more than one day to understand.

Thanks a lot. :)


Brucey(Posted 2009) [#2]
Are those really strings or char * (on the purebasic side)?

If they are really std::string or something similar you are going to have issues. Otherwise, you should be able to either convert your BlitzMax String to a CString or define the parameters as $z.

eg :
	Function comCreate:Int(name$z, progId$z) "win32"

or if they are wide (unicode) strings... use $w instead.


byo(Posted 2009) [#3]
Thanks for the fast reply.
It turns out I had checked the "Create unicode executable" under the Purebasic's options. Adding the "$w" worked perfectly.

Is there a ":String" alternative to "$w" or "$z". I like strongly typing my variables wiith var:String.

*offers beer*


plash(Posted 2009) [#4]
Is there a ":String" alternative to "$w" or "$z". I like strongly typing my variables wiith var:String.
I hear that!

Sadly, I do not think there are :(


byo(Posted 2009) [#5]
Well, good to know anyway. Thanks. :)
I'll get used to it, it's no big deal.


Zethrax(Posted 2009) [#6]
Something else to bear in mind when returning strings from a Purebasic dll, is that the returned strings should be global in scope. If you return them from a variable that is local to a function, the string may no longer exist at the point when it gets returned.