i have a variable of Cstring,need to convert it to wstring.
The MultiByteToWideChar function is the base level Win32 API function to do this. Whatever library or framework you are using may offer a more convenient function that wraps this operation.
Related
I have a Modelica external C function that calls a function that is in a .dll.
In the C function in the .dll I would like to make use of the ModelicaError() function. However when
#include ModelicaUtilities.h is included a number of errors occur.
What is the correct method for doing this?
I take it I'll need to link against an existing Dymola .lib, which one? What should DYMOLA_STATIC be defined as?
Or should I be compiling the .dll in such a way that these missing functions will be available after compilation with the model?
Any insight into this would be great, Thanks
From all what I know it is currently not possible in a tool-independent way to have shared objects (DLLs on Win) depending on ModelicaError (or any other functions of ModelicaUtilities). See https://github.com/modelica/ModelicaSpecification/issues/2191 for the open issue on the Modelica Language specification.
To use ModelicaError function in a dll you send the a pointer to the ModelicaError function. To do this from Dymola create a wrapper function that passes the pointer to the ModelicaError function to the dll function. For example MathLibraryWrapper:
#pragma once
#include "MathLibrary.h"
int fibonacci_next_int_wrap()
{
return fibonacci_next_int(&ModelicaError);
}
This calls the fibonacci_next_int function which is in MathLibary.cpp in the dll. This is modified to accept a pointer to the ModelicaError function.
int fibonacci_next_int(void(*mError)(const char *))
{
(*mError)("broken");
return (int)fibonacci_next();
}
If this is run it will immediately crash with "broken".
Why i cannot declare default arguments for member functions of a managed type or generic functions? C# 4.0 introduced Named and Optional Arguments; there is a similar thing for CLI?
I do not understand why is not possible to declare a method like this:
void Optional(int argument = 0);
And then when I call Optional(); the compiler does not translate this call into: Optional(0);.
It looks like the C++/CLI Compiler doesn't emit the correct IL directive for that. It doesn't emit the directive .param [1] = int32(0), which C# uses for recognizing default parameters. If you open the generated assembly in ILDasm, you'll see it.
A way that compiles would be to use the attributes Optional and DefaultParameterValue from the System::Runtime::InteropServices namespace, but C# doesn't use those for default parameters, so currently there's no easy way around creating an overload.
You can find the question asking about those Attributes here: https://stackoverflow.com/a/4974528/93652
I am working on C++/CLI wrapper for C static libary that is eventually used in C# application.
I have function like this in C Library.
long SubscriveEvent(void* handle,device name ,....);
long StartCaptureViceo(handle,...,...);
Here StartCaptureViceo () will use the handle from SubscriveEvent()
I nee to maintain some variable in C# for this void
Now what data type i should use in C++/CLI to Retain.
Please help me for this.
System::IntPtr
I building Wrapper in C++/CLI for C Static library to be used in .NET application through C#
I have function like this in C
long My_COM_Interface( PVOID hDevice,IUnknown **pUnknown);
How to declare IUnknown ** in C++/CLI
for first argument I am using IntPtr but Not able to find out the Replacement for IUknown.
I have another COM Data type GUID in another function this is also an issue for me.
Please Help me find the relacement for data type IUnknown and GUID.
There is no replacement.
C++/CLI understands native types just fine. Include the right header files, and you can use IUnknown* like always.
I'd refer to the APIs, e.g.
public static IntPtr GetIUnknownForObject(Object o);
This API can simply be used from C++/CLR and suggests you should use IntPtr^
try using parameter like;
ref object pUnknown
and use it like
MyObject o = pUnknown as MyObject
I have the following items in a structure:
- Dll name (absolute/relative path)
- Function name in the dll
- number of parameters
- Array of parameter types and values
With this information, I need to load the dll and call the function.
To load the dll I would use LoadLibrary.
To get the address of the function I would use GetProcAddress.
Call the function.
To unload the dll, FreeLibrary
Since the number of arguments of the function is dynamic, I am not sure about how the arguments need to be passed to the function.
Can anyone provide some details on how the parameters can be passed to the dll function?
Thanks and Regards,
V Karthick
Is it possible to pass the dictionary object (the one with the parameters) to some wrapper function and have that wrapper function call the actual function? It would probably save you a lot of headache and you could potentially use the preprocessor to generate the wrapper functions for you.