From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-17-2006 02:03 PM
07-17-2006 02:11 PM
07-17-2006 02:53 PM - edited 07-17-2006 02:53 PM
I'm not sure if this will work, but give it a try. For a string in a main cluster, when inputting the cluster to a DLL, extract the string from the main cluster, change the string to a byte array, change the array into a subcluster, rebuild the main cluster with the subcluster and the rest of the original cluster. Only drawback is that you must know how many characters there are in the string. The Array to Cluster function would have to be sized to be the number of characters in the string. The default setting is 9.
Message Edited by tbob on 07-17-2006 01:53 PM
07-18-2006 04:03 AM - edited 07-18-2006 04:03 AM
First you say you are calling a Win32 API function then you are using C calling convention. These two things are almost exclusive. Except for a few very special functions Microsoft is always using STDCALL for all its APIs. Most likely when you say you interface to Win32 API you do not mean this in the true sense as being a Windows API itself but just some arbitrary DLL that is compatible with Win32.
@tbob wrote:
I'm not sure if this will work, but give it a try. For a string in a main cluster, when inputting the cluster to a DLL, extract the string from the main cluster, change the string to a byte array, change the array into a subcluster, rebuild the main cluster with the subcluster and the rest of the original cluster. Only drawback is that you must know how many characters there are in the string. The Array to Cluster function would have to be sized to be the number of characters in the string. The default setting is 9.
Message Edited by tbob on 07-17-2006 01:53 PM
Message Edited by rolfk on 07-18-2006 11:05 AM
07-18-2006 04:22 AM
It's quite late but I still want to comment on this. Basically it does not matter that you pass the string pointer as parameter already if you want to return it as function parameter or if the string is located on the stack or in a constant data segement for instance.
@Klaus Vestergaard Kragelund wrote:
Some C code he refers to:
> CStr __stdcall SendRequest(long intComPort, CStr strID, CStr strType,
> CStr strParam, CStr strData, CStr strReturn)
> {
> LPVOID lpMsgBuf;
> char strErrMsg[1024];
> char strComPortName[25];
> char strRequestMessage[50];
> char strCheckSum[2];
>
> strcpy(strReturn, "");
>
> sprintf(strErrMsg, "Here is the function input: ComPort=%d, ID=%d,
> Type=%s, Parameter=%d.\n", intComPort, strID, strType, strParam);
> Log(strErrMsg);
>
> //Validate Input
> if (!ValidateInput(strID, strType, strParam, strData, strErrMsg))
> {
> FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
> FORMAT_MESSAGE_FROM_SYSTEM |
> FORMAT_MESSAGE_IGNORE_INSERTS,
> NULL,
> GetLastError(),
> MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
> (LPTSTR) &lpMsgBuf,
> 0,NULL);
> sprintf(strReturn,"%s:\n%s\n", strMessage, lpMsgBuf);
> LocalFree( lpMsgBuf );
> Log(strReturn);
> return strReturn;
> }
>
Off-hand - in the line just above "return strReturn". You are returning the
pointer of strReturn. But shouldn't the prototype be:
> CStr __stdcall SendRequest(long intComPort, CStr strID, CStr strType,
> CStr strParam, CStr strData, CStr *strReturn)
and without the return of strReturn. You have allready supplied the pointer
in the last argument - so why are you also using "Return" ?. I don't know
the CStr type - but I'm guessing it is a string.