Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this tool create .h & .lib files correspond to the C# function signature? #60

Closed
BlueSolei opened this issue Dec 13, 2017 · 4 comments
Labels

Comments

@BlueSolei
Copy link

Question:
Can this tool create a .h file with the C++ function's signature?
Can it create a .lib file, so I can statically link to this DLL and won't need to do all this dynamic loading LoadLibraryEx\GetProcAdddress boilerplate error-prone code?

@3F 3F added the question label Dec 14, 2017
@3F
Copy link
Owner

3F commented Dec 14, 2017

Can this tool create a .h file with the C++ function's signature?

You can get and format the list of exported functions as you need through -pe-exp-list (v1.6-RC)

#55 (comment)

DllExport -pe-exp-list bin\Debug\regXwild.dll

But without full signatures. It easy to implement for .net environment via Cecil etc., but for unmanaged C++ we need to implement translation to equivalents for marshaled types, and so on.

Can it create a .lib file, so I can statically link to this DLL and won't need to do all this dynamic loading

You can generate additional .exp & .lib when $(DllExportGenExpLib = true) (for Wizard see same option "Generate .exp + .lib ...") but of course only to reference exported definitions.

MyInit -> DllExportClassLibrary1.dll

00000AA0  4C 01 0A D8 32 5A 23 00 00 00 01 00 08 00 5F 4D  L..Ш2Z#......._M
00000AB0  79 49 6E 69 74 00 44 6C 6C 45 78 70 6F 72 74 43  yInit.DllExportC
00000AC0  6C 61 73 73 4C 69 62 72 61 72 79 31 2E 64 6C 6C  lassLibrary1.dll
00000AD0  00 0A 2F 30 20 20 20 20 20 20 20 20 20 20 20 20  ../0            

@BlueSolei
Copy link
Author

So how should I know what is the unmanaged c++ counterpart to an exported C# function?
My problem is that it seems I need to guess the signature.
Obviously, the DllExport knows what the right signature, as it creates an exported unmanaged function to serve as a proxy to the C# function, IIUC.
For example, if the C# signature is:

[DllExport]
public static void print(string str) {}

I guessed that if I call it as:

void print(const char* str) {}

it will work.
And fortunately, it worked :-)
But when I wish to find the unmanaged signature of:

[DllExport]
public static void printArr(string[] str) {}

I didn't find the right unmanaged signature :-(
Do I miss something on how to use this tool?

@3F
Copy link
Owner

3F commented Dec 15, 2017

@BlueSolei Only primitive types and read more about PInvoke.

Related:

That is, use pointer to allocated string etc.

[DllExport]
public static void print(IntPtr ptr) {}

@3F 3F added the unclear label Jul 16, 2018
@3F
Copy link
Owner

3F commented Jul 16, 2018

I updated solutions for how to use complex types and strings between unmanaged and managed environments:

But going back to the original question from this issue!

if this was not a misunderstanding and if it really is needed to someone, well, please clarify additional details. Probably I can implement something if this will be justified for some cases.

@3F 3F closed this as completed Dec 15, 2019
@3F 3F removed the unclear label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants