0

I'm trying to create a dll from a C++ project

I followed this link:

    using a class defined in a c++ dll in c# code

And I encountered a problem:

DLL entry point "int __cdecl main (int, wchar_t * * const)" (? Main @@ $$ HYAHHQAPA_W @ Z) cannot be managed; compile to native

I changed the int main to:

int _tmain (int argc, _TCHAR * argv [])

But I ran into a problem:

unresolved external symbol _main
jmq
  • 1,559
  • 9
  • 21
Rachel
  • 15
  • 7
  • 2
    There's no `main` in a dynamic library. – Jesper Juhl Jun 01 '20 at 13:18
  • 3
    A DLL should not have a `main` function. It should have a [`DLLMain`](https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain) function. – Some programmer dude Jun 01 '20 at 13:18
  • If I download the main I get an unresolved external symbol _main error – Rachel Jun 01 '20 at 13:20
  • Are you using .net / CLR with your dll? Or is this going to be used on standard `c++`? – drescherjm Jun 01 '20 at 13:20
  • 1
    ***If I download the main I get an unresolved external symbol _main error*** I would guess you selected the wrong project type for a native c++ dll. – drescherjm Jun 01 '20 at 13:21
  • I changed properties instead of .exe to dll – Rachel Jun 01 '20 at 13:22
  • You probably want to go through this tutorial: [https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019) – drescherjm Jun 01 '20 at 13:24
  • First of all the message "cannot be managed" indicates that you're building a managed project (C++/CLI). Secondly, if the project requires a `main` function then you're building an application and not a DLL. – Some programmer dude Jun 01 '20 at 13:25
  • I have an existing project and I can't build another one – Rachel Jun 01 '20 at 13:35
  • 1
    If you are using Visual Studio then your solution can contain many projects. The source files could be shared between projects (although it's better to put common code into their own DLL projects and then reuse the DLL's instead). – Some programmer dude Jun 01 '20 at 13:43

0 Answers0