Would one of you fine people who knows C be willing to do me a favor?

Would one of you fine people who knows C be willing to do me a favor?  
I have a *.h file that I've converted to be a *.pas file, but for the life of me, I can't make it work.  

Would any of you be willing to take a look at what I've done?  It's not very big, maybe a dozen functions.  It's a bit ugly with lots of *Char, but it shouldn't be too hard.

If anyone can help, I'd be much obliged.

Comments

  1. I can try and give a hand, too - I haven't been doing C headers for quite a while but I think I can still do it :)

    A

    ReplyDelete
  2. If it's not too copyrighted then you could put the files up on http://pastebin.com/ and see what people come up with.

    ReplyDelete
  3. After D2009, translating C/C++ char* parameter sometimes isn't simple.

    Not just convert char* into PChar or PAnsiChar, but sometimes need wrapping corresponding API into different function signatures for convenience or preventing from error. (may depend on platform or framework usage)

    If you need any further help, please don't hesitate to let me know.  :)

    ReplyDelete
  4. Sam Shaw Pointers from c/c++ are not always compatible to PChar, because PChar is a delphi specific typedef to either PAnsiChar or PWideChar. (Depends on compiler version and settings.)

    Translate char* to PAnsiChar and wchar_t* to PWideChar and you should be out of trouble regarding char pointers.

    ReplyDelete
  5. Udo Sommer yes,what you said is part of what I meant.

    Moreover, converting C char pointer to PAnsiChar maybe still buggy.

    Considering someone just type casts string into PAnsiChar as parameter, it may get in trouble since string is unicode and will be automatically convert to Ansistring by system codepage. Some characters may "lost" after converting.

    IMHO, translate C char pointer into DELPHI typeless pointer is safer. In C char pointer, it doesn't mean the data is really a char type. It just means a pointer points to "a single bye width" data and increasing the pointer value just shift one byte memory position.

    Thus C char pointer still can store Unicode string as long as function api asking for extra length parameter to indicate the buffer length, which no longer limit data to null-terminated string.

    The best policy is wrapping raw API into one or more "bridge" APIs. That is, for example, into three functions: one for input string, one for Ansitring, the other for TBytes as input parameter. Wrapping implementation is using TEncoding class to convert data into TByte then cast into typeless pointer to map C char pointer.

    What I said is just an example and applicable for D2009 or later. The real implementation depends on C API's functionality.

    FYR.

    ReplyDelete
  6. Nick Hodges Send it my way (via email) and I'll take a look. Can you expand on how it doesn't work - the compiler or linker don't like it, functionality is wrong, or it crashes?

    ReplyDelete
  7. Nick Hodges  I'd also like to take a look

    ReplyDelete
  8. Thanks, guys.  Send me an email at nick.hodges@veeva.com and I'll send you the files. 

    Thanks so much.

    Nick

    ReplyDelete

Post a Comment