People, I am calling an external DLL function into my code. One of the parameters is the Filename, so the function parameter expects a PAnsiChar() / convertion. All look likes to be fine, but the generated file gets only the 1st char, so if name it "myfile.dat" I will see a "m" file on the folder.

People, I am calling an external DLL function into my code. One of the parameters is the Filename, so the function parameter expects a PAnsiChar() / convertion. All look likes to be fine, but the generated file gets only the 1st char, so if name it "myfile.dat" I will see a "m" file on the folder.
I am using XE5. Should I call the procedure developer for help? That DLL can be used in a lot of examples, since C# to Java, including Delphi.
Thank you.

Comments

  1. Do You use "stdcall" on the external?

    ReplyDelete
  2. Just to cover the obvious but you are passing the file name by PAnsiChar(filename), right?

    ReplyDelete
  3. Yes: function thefunction(FileName: PAnsiChar): integer; cdecl; external 'thedll.dll'; and Yes, PAnsiChar(filename) :)

    ReplyDelete
  4. Do you have compiler warnings or hints? I think it should be: PAnsichar(ansistring(filename))

    ReplyDelete
  5. André Mussche is on the ball here, you have a unicode string that you're trying to pass as a ansi string pointer, however, data at PAnsiChar(fileName) looks:

    [m] [0x00] [y] [0x00] ...

    since the second byte is NULL, that's where the DLL stops to read all other bytes in your file name.

    ReplyDelete
  6. André Mussche Yes man, that did the trick. Unicode issue :)  Thank you

    ReplyDelete
  7. Magno Lima Nice :), but for me, the important question is: did delphi complain about a "suspicious ansistring conversion" or something like that?

    ReplyDelete
  8. YES! Blame on me! :)
    [dcc32 Warning] uMain.pas(256): W1044 Suspicious typecast of string to PAnsiChar

    ReplyDelete
  9. Magno Lima Right :) No kidding: always make sure you have no hints or warnings!

    ReplyDelete
  10. Hints are just messy, while warnings are a sign of a clear and present danger.

    ReplyDelete
  11. Lars Fosdal Hints can tell you very important things too, e.g. you declare a variable called "MyName" but later on by mistake use the property "Name" instead. The compiler will hint you, that the variable is declared but never used.

    ReplyDelete
  12. Daniela Osterhagen - That is true.  I prefer to keep my code hint and warning free, but when cleaning out someone elses code, it is the warnings that take prio.

    ReplyDelete
  13. Meanwhile a successful build here produces some 10k warnings and hints... It's my summer mission to do something about that...

    ReplyDelete
  14. Lars Fosdal probably too many for a stable IDE ((:
    On one of my 50k+ LOC the IDE fails to start auto-complete and all kinds of artifacts appear all over the place...

    ReplyDelete
  15. We have a 600k+ line project, and it has artifacts (such as a unit with no blue dots for generated code), but auto-complete seems to keep working.

    ReplyDelete
  16. Lars Fosdal 600k+ just project code, or the sum with used components?

    I wonder if my issue has anything to do with the fact that there are over 200 units in the project...?

    ReplyDelete
  17. Actually I try dont care for warnings out of my own code, ie. 3rd party comps, unless I see it will cause any trouble or avoid it to compile...

    ReplyDelete
  18. Magno Lima but it is easier to spot problems early if you have no hints and warnings at all and suddenly you get a warning or hint... (my colleague even has turned on "error on hints and warnings"!)

    ReplyDelete
  19. Lars Fosdal I haven't done a proper count, I'm guessing about 200kLOC of our own. When building it goes to about 500kLOC, but I think that includes the JCL units we use and such things.

    ReplyDelete
  20. Dorin Duminica - around 150K lines are project specific in the server.  Around 250K in the client app.

    ReplyDelete
  21. Lars Fosdal still a ton (: I've used CnPack in D2010 which has a plugin(?) capable of doing all the project source counts, so, effective code(no empty lines, no comments, etc.) was around 5XK LOC, since then, we've moved to XE6, there was no CnPack at the time, so I have no idea of exact count at this time, however, it's only growing (:

    ReplyDelete

Post a Comment