Convert Unmanaged C ++ Code to C #

Anyone with pointers to a tool / utility for converting unmanaged C ++ to C #? I tried http://www.pinvoke.net/ , but I can not find a link to this API AddUsersToEncryptedFileon this question .

+3
source share
4 answers

In general, this is really complicated because C ++ offers different functions than C #: templates, friends, null-terminated strings, unmanaged pointers, COM, etc. not to mention that C ++ parsing is a bitch of work.

To do this, you need a complete C ++ analyzer with name and type resolution, a set of ideas on how to convert each construct (problematic or not) into equivalent C # code, a way to encode these ideas into automated translation steps, and a plan on what to do with those parts of the code that don’t translate well (usually “fix it manually”).

Using the DMS Software Reengineering Toolkit , which provides all the necessary mechanisms, my company, Semantic Designs, actually built such a tool, but never used it, for a large client who wanted to move 800K SLOC C ++ to C #. Approximately 2/3 of the project’s implementation, the client had a rearrangement in the management of the bird cage, and the new managers decided not to continue saving money (the tool itself was done well).

+2

:

, # -SQLite .NET

SQLite - C, .

+2

API? PInvoke Interop Assistant, DIY. .

struct EFS_CERTIFICATE_BLOB
{
    public int dwCertEncodingType;
    public int cbData;
    public IntPtr pbData;
}

struct ENCRYPTION_CERTIFICATE
{
    public int cbTotalLength;
    public IntPtr pUserSid;
    public IntPtr pCertBlob;
}

struct ENCRYPTION_CERTIFICATE_LIST
{
    public int nUsers;
    public IntPtr pUsers;
}

[DllImport("advapi32.dll", CharSet=CharSet.Unicode)]
static extern uint AddUsersToEncryptedFile(string lpFileName, ref ENCRYPTION_CERTIFICATE_LIST pUsers);
+1

++ #, , , ++ ++/CLI. # (.. ), , ).

An alternative to converting to C ++ / CLI would be to wrap existing unmanaged C ++ code using SWIG , however, migration will be more difficult using this method.

+1
source

Source: https://habr.com/ru/post/1716563/


All Articles