A
Arthur Mnev
The scenario:
a library written in C;- source avaialble.
the end cosumer is C# code.
There are a few different approaches:
1) Compile C code as .lib and link it to C++ library, write a managed
wrapper around it and off we go.
2) Compile native C DLL and write a wrapper in C# through P/Invoke
The real quesiton is which one is better? My basic analysis:
C++ Managed DLL + C code = buggy implementation by Microsoft. There
are issues related to OS level locks placed during dllMain execution
(which has to happen because of CRT). Microsoft's work arounds seem to
do the job to a point, yet there is still a possibility of deadlocking
(see microsofts' articles on the subject)
Even assuming that those issues are fixed - still the same question is
in place:
One of the functions that is being executed follows the signature:
"C"
void myfunct(char* dest, int* dsize_t, const char* src, int ssize_t);
memory for dest must be preallocated, the size of it is unknown until
the function returns when dsize_t can be examined.
Consequently, when writing a wrapper, whether it is C++ or C# I have
to execute the function, then examine the data and then copy the data,
allocate managed buffer of the appropriate size and then copy the
data.
Data copy required will need to be performed ether way, regardless of
whether it is C++ or C# code. The wrapper could be written in C++ with
static linking or through C# with dynamic linking. If someone has a
good technical answer - please let me know what your thoughts are.
Initially, assume that Microsoft's dllMain bugs are fixed and the
static library requiring CRT can actually be linked to managed class
with no issues.
As a side question; does someone have a good answer as to what in the
world is the real technical difference between supplying "ref int
variable" vs "int* variable" from unsafe C# code.
- Arthur
a library written in C;- source avaialble.
the end cosumer is C# code.
There are a few different approaches:
1) Compile C code as .lib and link it to C++ library, write a managed
wrapper around it and off we go.
2) Compile native C DLL and write a wrapper in C# through P/Invoke
The real quesiton is which one is better? My basic analysis:
C++ Managed DLL + C code = buggy implementation by Microsoft. There
are issues related to OS level locks placed during dllMain execution
(which has to happen because of CRT). Microsoft's work arounds seem to
do the job to a point, yet there is still a possibility of deadlocking
(see microsofts' articles on the subject)
Even assuming that those issues are fixed - still the same question is
in place:
One of the functions that is being executed follows the signature:
"C"
void myfunct(char* dest, int* dsize_t, const char* src, int ssize_t);
memory for dest must be preallocated, the size of it is unknown until
the function returns when dsize_t can be examined.
Consequently, when writing a wrapper, whether it is C++ or C# I have
to execute the function, then examine the data and then copy the data,
allocate managed buffer of the appropriate size and then copy the
data.
Data copy required will need to be performed ether way, regardless of
whether it is C++ or C# code. The wrapper could be written in C++ with
static linking or through C# with dynamic linking. If someone has a
good technical answer - please let me know what your thoughts are.
Initially, assume that Microsoft's dllMain bugs are fixed and the
static library requiring CRT can actually be linked to managed class
with no issues.
As a side question; does someone have a good answer as to what in the
world is the real technical difference between supplying "ref int
variable" vs "int* variable" from unsafe C# code.
- Arthur