c# - Unmanaged to Managed returning object that contains BOOL -
I am using a C + + DLL function to call PInvoke in C # in a returned object But the price is never right. I have read many articles on this, which tells that C ++ bool is 1 byte while C # Bull has 4 bytes. I have also seen how to solve this problem when a function gives a force, But my function is returning an object in which there is a boole. I am not getting any articles that handle this situation.
For example, I have two strings for the input of unmanaged DLL functions and one that defines the output:
public structure MyInput {public int id; Public string model number; } Public framework MyOutput {public int SomeValue; Public Double A Aalu; Public Bull ISIELD; } [DllImport ("MyUnmanaged.dll", EntryPoint = "? Unit @@yah? AUMyOutput @@ UMyInput @@@ Z")] Public stable extern MyOutput unit (Ref MyInput UnitInput);
MyOutput does not work as defined above because the signature is invalid so I changed it:
public int isvalid;
This invalid signature takes care of the error, but IsValid does not have the value 0 or 1 as I would expect. Instead, it is -858993664. I have also tried to change the byte, but the returned value is always 0.
I do not know how to martilize the bull within the MyOutput straight or how to define it so that I have valid Bull - 1 or 0.
BTW, I have no control over unmanaged DLL ...
Can someone give me the idea of defining me? MyOutput struct inside bool?
Edit
I was given all of them. DLL and .h for unmanaged DLL. In .h, the question is defined bool as:
bool isvalid; According to this, your unmanaged function has this signature:
Then your C # declaration should be:
[DllImport ("MyUnmanaged.dll" , EntryPoint = "Unit @@YA? AUMUTPUT @@UMI input @@ @Z, Calling Convention = Calling Convention. CDCL) Public Static Extension MyOutput Unit (MyanPot Unit Input);
In other words, you have a wrong calling conference , And was passing the value instead of ref
from the parameter.
You also came to know that your return value can not be martial, because in it There is a bool
field, you need to change the byte
or int
on it, which is an unmanaged structure declaration, it looks based on your edits , That declares the header file as bool
, which is a single bye So, therefore, you should use bytes
.
Comments
Post a Comment