const char*?

  1. 3 months ago

    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?

  2. Norman P

    Jun 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog
    Edited 3 months ago

    CString implies "char *"

    dont think there is any way to force "const" though

    and you can actually skip declaring a CString :P

    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

  3. 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.

  4. Julian S

    Jun 6 Pre-Release Testers, Xojo Pro UK

    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.

  5. Andrew L

    Jun 6 San Francisco, CA, USA

    @Sean A When I try that it runs but gives me back a "1"

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

  6. Norman P

    Jun 6 Pre-Release Testers, Xojo Pro great-white-software.com/blog

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

  7. 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.

  8. Julian S

    Jun 6 Pre-Release Testers, Xojo Pro UK
    Edited 3 months ago

    Or try this

    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(p)
  9. @Julian - thanks so much again. it runs with the cat char(0) but gives the "1" return to "ok".

  10. Norman P

    Jun 7 Pre-Release Testers, Xojo Pro great-white-software.com/blog

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

    there's something else going on

  11. Ulrich B

    Jun 8 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    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.

or Sign Up to reply!