Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 25 FEB 2004 02:00:45PM Tony Splaver wrote:

Hello,

OK, this is a first for me… I need some help with OI.

I am trying to make function calls to a VC++ DLL that I wrote a year ago (DirectPrint.DLL), and it works perfect with OI 4.x.

Here is the VC++ declaration:

#define DIRECTPRINT_API __declspec(dllexport)

DIRECTPRINT_API int DirectStart(LPSTR lpPrinterName, LPSTR lpTitle);

And here is the OI declaration:

INT STDCALL DirectStart(LPCHAR,LPCHAR)

And here is the line of code that fails in Basic+:

retval=DirectStart("","Test report")

When I call the DirectStart() function from Basic+, it works OK. But when I was debugging the VC++ DLL I discovered that string parameters (LPSTR) contained invalid data from OI. I though I might need to do a LockVariable and GetPointer, but that also failed to pass the string data from OI to my DLL correctly. I tried changing the calling convention in my VC++ DLL to C and Standard, and I tried other string data types (char *, LPCSTR, LPWSTR), but it did not help.

After closer examination of the data pointed to by the LPSTR, I discovered the problem – The strings were not NULL terminated. So I changed my Basic+ code to:

retval=DirectStart("":Char(0),"Test report":Char(0))

and everything started to work perfectly again!

So here is my question:

Does anyone know if the DLL calling wrapper in OI changed in version 7.0? Because it appears that previous versions automatically appended the NULL to LPCHAR parameters. I understand that it is a good idea to always terminate strings when calling DLLs, but it was not required in previous versions. It seems a bit painful to make us put the NULL on each string parameter.

Sincerely,

Tony Splaver

Splaver Software


At 25 FEB 2004 02:16PM The Sprezzatura Group wrote:

Tony

Earlier OIs GPFed if the null wasn't there so I guess we just got into the habit of including it. Prototyping has been extended - check out SRPCS's White Paper on the subject at http://www.srpcs.com/resources/articles/DLL_Parameter_Types_in_OpenInsight.pdf.

The Sprezzatura Group

World Leaders in all things RevSoft


At 25 FEB 2004 03:16PM Tony Splaver wrote:

OI 4.x did not have any problems with non-NULL terminated strings (I think you are referring to OI16). I think it is a bit painful to require the NULL character on each string variable… for example, in VB you do not need to add the NULL character, because VB knows to always put it on for you when you declare a variable as String.

So I am wondering if OI 4.x had a "bug" that allowed you to not use the NULL, and they fixed it in 7.0.


At 25 FEB 2004 06:39PM Jim Vaughan wrote:

You now have LPCHAR and LPSTR.

This is what Pat said:

"Only the return value of LPCHAR has to change if it really is a null-terminated string you want returned. The LPCHAR parameter works pretty much like it always has, although if you want the engine to automatically null-terminate the string for you, then you might want to use LPSTR."


At 25 FEB 2004 11:35PM Pat McNerthney wrote:

Tony,

Read the white paper Sprezz linked to.

Pat


At 26 FEB 2004 04:13PM Tony Splaver wrote:

  • third_party_content/community/commentary/forums_nonworks/f262e0d088cbd0b985256e45006870a2.txt
  • Last modified: 2023/12/28 07:40
  • by 127.0.0.1