Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualATC

Posted 22 October 2012 - 11:33 AM

Geez, sometimes I can be a major idiot lol...

It was all because I forgot to use C-linkage and add my custom _DLLEXPORT modifier to things. So the problem is now solved...

If anyone else ever has this problem, here's what you need to do:

1) Go to Configuration Manager and set the proper project dependencies (in my case "ConsoleTest" depends on "ATCFramework")
2) Under your project properties of your consuming application, go to "Common Properties" and click "Add Reference"; then reference your DLL
3) Specify C-type linkage and export your classes, structures and functions like so:

[source lang="cpp"]extern "C"{ typedef struct __declspec(dllexport) MY_STRUCT { int X, Y; // whatever } MyStruct, *MyStructPTR;};[/source]

You only need to do this in your header files... not in your .c or .cpp implementation files. It's as simple as that! :-)

Have fun,

--ATC--

EDIT:

Note: Forcing C-linkage is not absolutely necessary for C++, but you are required to do so to consume something from C code. Otherwise you will get some name mangling and C code won't know what to do. So it's just good practice imo to force C-linkage in these situations. I also think it helps if you ever want to debug at the assembly/machine code level.

As an added note I don't think a function with C-linkage can return a C++ class instance. So watch what you're doing or you'll get weird linker errors that may or may not make any sense.

#4ATC

Posted 22 October 2012 - 11:32 AM

Geez, sometimes I can be a major idiot lol...

It was all because I forgot to use C-linkage and add my custom _DLLEXPORT modifier to things. So the problem is now solved...

If anyone else ever has this problem, here's what you need to do:

1) Go to Configuration Manager and set the proper project dependencies (in my case "ConsoleTest" depends on "ATCFramework")
2) Under your project properties of your consuming application, go to "Common Properties" and click "Add Reference"; then reference your DLL
3) Specify C-type linkage and export your classes, structures and functions like so:

[source lang="cpp"]extern "C"{ typedef struct __declspec(dllexport) MY_STRUCT { int X, Y; // whatever } MyStruct, *MyStructPTR;};[/source]

You only need to do this in your header files... not in your .c or .cpp implementation files. It's as simple as that! :-)

Have fun,

--ATC--

EDIT:

Note: Forcing C-linkage is not absolutely necessary for C++, but you are required to do so to consume something from C code. Otherwise you will get some name mangling and C code won't know what to do. So it's just good practice imo to force C-linkage in these situations. I also think it helps if you ever want to debug at the assembly/machine code level.

As an added note I don't think a function with C-linkage can return a C++ class instance. So watch what you're doing on you'll get weird linker errors that may or may not make any sense.

#3ATC

Posted 20 October 2012 - 11:50 PM

Geez, sometimes I can be a major idiot lol...

It was all because I forgot to use C-linkage and add my custom _DLLEXPORT modifier to things. So the problem is now solved...

If anyone else ever has this problem, here's what you need to do:

1) Go to Configuration Manager and set the proper project dependencies (in my case "ConsoleTest" depends on "ATCFramework")
2) Under your project properties of your consuming application, go to "Common Properties" and click "Add Reference"; then reference your DLL
3) Specify C-type linkage and export your classes, structures and functions like so:

[source lang="cpp"]extern "C"{ typedef struct __declspec(dllexport) MY_STRUCT { int X, Y; // whatever } MyStruct, *MyStructPTR;};[/source]

You only need to do this in your header files... not in your .c or .cpp implementation files. It's as simple as that! :-)

Have fun,

--ATC--

EDIT:

Note: Forcing C-linkage is not absolutely necessary for C++, but you are required to do so to consume something from C code. Otherwise you will get some name mangling and C code won't know what to do. So it's just good practice imo to force C-linkage in these situations. I also think it helps if you ever want to debug at the assembly/machine code level.

#2ATC

Posted 20 October 2012 - 06:23 PM

Geez, sometimes I can be a major idiot lol...

It was all because I forgot to use C-linkage and add my custom _DLLEXPORT modifier to things. So the problem is now solved...

If anyone else ever has this problem, here's what you need to do:

1) Go to Configuration Manager and set the proper project dependencies (in my case "ConsoleTest" depends on "ATCFramework")
2) Under your project properties of your consuming application, go to "Common Properties" and click "Add Reference"; then reference your DLL
3) Specify C-type linkage and export your classes, structures and functions like so:

[source lang="cpp"]extern "C"{ typedef struct __declspec(dllexport) MY_STRUCT { int X, Y; // whatever } MyStruct, *MyStructPTR;};[/source]

You only need to do this in your header files... not in your .c or .cpp implementation files. It's as simple as that! :-)

Have fun,

--ATC--

#1ATC

Posted 20 October 2012 - 06:22 PM

Geez, sometimes I can be a major idiot lol...

It was all because I forgot to use C-linkage and add my custom _DLLEXPORT modifier to things. So the problem is now solved...

If anyone else ever has this problem, here's what you need to do:

1) Go to Configuration Manager and set the proper project dependencies (in my case "ConsoleTest" depends on "ATCFramework")
2) Under your project properties of your consuming application, go to "Common Properties" and click "Add Reference"; then reference your DLL
3) Specify C-type linkage and export your classes, structures and functions like so:

[source lang="cpp"]extern "C"{ typedef struct __declspec(dllexport) MY_STRUCT { int X, Y; // whatever };};[/source]

You only need to do this in your header files... not in your .c or .cpp implementation files. It's as simple as that! :-)

Have fun,

--ATC--

PARTNERS