AutoIt:
- What gave you the idea that your DllStructCreate pattern is in any way valid?
- I can see where the documentation might not be clear on this, but struct cannot be a return type for DllCall. There is no way for AutoIt to know what the structure is supposed to be.
C:
- fff needs to be a pointer, which you've done in the AutoIt side. However in your DLL you're first assigning it values as a regular structure, then you are completely disregarding it, and creating a new structure in retval and trying to return that, which as I've mentioned (and Valik has also), you cannot do.
AutoIt: - What gave you the idea that your DllStructCreate pattern is in any way valid? - I can see where the documentation might not be clear on this, but struct cannot be a return type for DllCall. There is no way for AutoIt to know what the structure is supposed to be.
C: - fff needs to be a pointer, which you've done in the AutoIt side. However in your DLL you're first assigning it values as a regular structure, then you are completely disregarding it, and creating a new structure in retval and trying to return that, which as I've mentioned (and Valik has also), you cannot do.
Never return a structure from a function. There's your clue.
You are both right, got the the code to work with int datatype but i want to get strings from the struct with the Char * but when i create the struct in autoit it keeps on erroring.
You are both right, got the the code to work with int datatype but i want to get strings from the struct with the Char * but when i create the struct in autoit it keeps on erroring. The Updated C++ code:
You probably need to post autoit code and more stuff too. What is doors?
The doors is a variable with the TiXmlAttribute* datatype it was from the test file that came with TinyXml and just left it like that in my dll file. Anyways got the code to return the string I wanted but how am I supposed to go with the size of the string, say for E.G. the user has more than 5 char in his string and declare 5 in my struct and in autoit struct and in my dll how I am supposed to make the buffer larger without re compiling the dll or the autoit exe.
If the above is not possible can i least get a array from "return char * array" from C++ dll then in autoit which will be returned by $aRet[0].
The doors is a variable with the TiXmlAttribute* datatype it was from the test file that came with TinyXml and just left it like that in my dll file. Anyways got the code to return the string I wanted but how am I supposed to go with the size of the string, say for E.G. the user has more than 5 char in his string and declare 5 in my struct and in autoit struct and in my dll how I am supposed to make the buffer larger without re compiling the dll or the autoit exe.
If the above is not possible can i least get a array from "return char * array" from C++ dll then in autoit which will be returned by $aRet[0].
What you want is dynamic memory. But its truly going to be a bitch, since you gotta decide ownership, who's cleaning up etc, and you're doing it inbetween two languages. Normally, the user of the library should allocate the memory to the library function (xmlgetfirstattribute). Since you dont know how much you're going to need, you either have to a. supply a large enough buffer for all cases b. request the size from a helper function.
b is the usual way, because a often results in buffer overruns. Here's how you could implement it in the dll:
The other option is to keep it as one function but use the windows API method of passing a special value for the structure pointer, like NULL, which will simply return the required size of the buffer. Then you call the same function again with the pointer to your actual structure.
The other option is to keep it as one function but use the windows API method of passing a special value for the structure pointer, like NULL, which will simply return the required size of the buffer. Then you call the same function again with the pointer to your actual structure.
You are right, but i've always felt it was awkward to have one function do two different things. Also, this function needs to return 2 values, which you can make a workaround for, but it wont be much prettier than 2 functions, i guess.
Thank you Shaggi i will use this, but you made a mistake in the autoit code but i fixed it, where it shows DllStructGetData($XmlAttributeInfo,"x") it returns the pointer which is something like the following 0x332544. in order to show the text i moved the buffers and asigned them a variable, look below.
The other option is to keep it as one function but use the windows API method of passing a special value for the structure pointer, like NULL, which will simply return the required size of the buffer. Then you call the same function again with the pointer to your actual structure.
wraithduThanks for the suggestion but I thinkShaggisolutions is more efficient on the memory.
Thank you Shaggi i will use this, but you made a mistake in the autoit code but i fixed it, where it shows DllStructGetData($XmlAttributeInfo,"x") it returns the pointer which is something like the following 0x332544. in order to show the text i moved the buffers and asigned them a variable, look below.
is the same when you call both functions, i dont know the rest of your code but if this could change you might want to consider adding that pointer to the struct also, so you wont experience buffer overflows.
is the same when you call both functions, i dont know the rest of your code but if this could change you might want to consider adding that pointer to the struct also, so you wont experience buffer overflows.
Renamed Then Main POST to "Need help with: dll struct, Display Unicode String, Convert dll to x64" from "Need help with dll struct" to avoid starting a new topic.
Now that I have finished creating the 32 bit DLL but has one issue with Unicode, the thing is that i don't know how to go with it. When the file has been read by the TinyXml with Unicode encoding it returns the text by const char* which I then use the function "UTF8_to_WChar" mentioned on "http://www.cplusplus.com/forum/general/7142/" which will give me wchar_t . Is this the right way to go with it?
Another thing is that when I want to make the 32 bit DLL to 64 bit, do I need to change any code from the DLL in order to make the DLL work or just change the complier options of the 64 bit compiler.