const char*?

I have this in a .dll’s header:
DLL int PluginOpenFile(const char* inFilename);

So I :
Dim FileName As CString = “B0032.sm” (this is copied inot the app main on a build script CopyFileStep)

soft Declare Function PluginOpenFile Lib “slvsPlugin.dll” (ByRef FileName As CString) As Integer

result = PluginOpenFile( FileName )

…but this hangs inside the .dll and I have to “EndTask”. If I leave the ByRef out ogf the declare, it runs but returns an error (1)
I know I am bungling the ptr but how?

CString implies “char *”

dont think there is any way to force “const” though

and you can actually skip declaring a CString :stuck_out_tongue:

Dim FileName As String = "B0032.sm" 
soft Declare Function PluginOpenFile Lib "slvsPlugin.dll" (FileName As CString) As Integer

but dont make it byref CString as that is more like *(char *) - ptr to ptr

Thanks Norm, I must have something else wrong. When I try that it runs but gives me back a “1” - no bueno… I wonder if it cant find the file but I CopyFileStep it in there with the .dll and its Init fine.

If you are working in Unicode, you’ll need to use WString instead of CString, it all depends on the way the dll was made.

Soft Declare Function PluginOpenFile Lib "slvsPlugin.dll" (FileName As WString) As Int32

should be ok.

This is coming from the function itself. Check the documentation for the function to see what it means.

this is his dll he, or his company, wrote :slight_smile:

well said Norm, and thank you all. I am just a hobbyist at this point and I am using a DLL from a team I know but it is not a commercial thing, not well docuemtned but I did ask them to clarify the return values.

@Julian - thanks again, i tried that setup but no cigar.

I have offered a “bounty” for someone who knows this kind of work via the consulting link on xojo.com so if anyone wants to DM me and take some $ for helping me Im not opposed to paying for what i dont know.

Or try this

[code]Dim tmp As MemoryBlock
tmp = “B0032.sm” // might need +chr(0) on the end, not sure

Dim p As Ptr = tmp

Soft Declare Function PluginOpenFile Lib “slvsPlugin.dll” (FileName As Ptr) As Int32

Dim ok As Int32
ok = PluginOpenFile§[/code]

@Julian - thanks so much again. it runs with the cat char(0) but gives the “1” return to “ok”.

yeah you should not need to manually append the chr(0)

there’s something else going on

I‘d say it‘s not the declare (everytime you received a response you had it basically right) but the filename. Looks like the file is not at the right location for the dll to find it, or in other words you‘ll have to add the full path information to the string.