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.
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.
Do You use "stdcall" on the external?
ReplyDeleteJust to cover the obvious but you are passing the file name by PAnsiChar(filename), right?
ReplyDeleteYes: function thefunction(FileName: PAnsiChar): integer; cdecl; external 'thedll.dll'; and Yes, PAnsiChar(filename) :)
ReplyDeleteDo you have compiler warnings or hints? I think it should be: PAnsichar(ansistring(filename))
ReplyDeleteAndré 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:
ReplyDelete[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.
André Mussche Yes man, that did the trick. Unicode issue :) Thank you
ReplyDeleteMagno Lima Nice :), but for me, the important question is: did delphi complain about a "suspicious ansistring conversion" or something like that?
ReplyDeleteYES! Blame on me! :)
ReplyDelete[dcc32 Warning] uMain.pas(256): W1044 Suspicious typecast of string to PAnsiChar
Magno Lima Right :) No kidding: always make sure you have no hints or warnings!
ReplyDeleteHints are just messy, while warnings are a sign of a clear and present danger.
ReplyDeleteThank you for advise! :)
ReplyDeleteLars 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.
ReplyDeleteDaniela 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.
ReplyDeleteMeanwhile a successful build here produces some 10k warnings and hints... It's my summer mission to do something about that...
ReplyDeleteHow many LOC in that build?
ReplyDeleteLars Fosdal probably too many for a stable IDE ((:
ReplyDeleteOn one of my 50k+ LOC the IDE fails to start auto-complete and all kinds of artifacts appear all over the place...
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.
ReplyDeleteLars Fosdal 600k+ just project code, or the sum with used components?
ReplyDeleteI wonder if my issue has anything to do with the fact that there are over 200 units in the project...?
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...
ReplyDeleteMagno 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"!)
ReplyDeleteLars 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.
ReplyDeleteDorin Duminica - around 150K lines are project specific in the server. Around 250K in the client app.
ReplyDeleteLars 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