0

I am learning how to use dlls and how to export them. I have created a small program that calls the different components(classes, methods, functions, ect.. ) of my dll file to use them. When I build the project I get no problem, but when I compile the test code I get this error.

Insert image description here

Error translation: {The procedure entry point "?Start@K_WrapperTeigha_DXF_DWG@@QAEXXZ" was not found in the DLL "C:\Users\zboussaid\source\repos\WrapperTester\Debug"}.

The image shows that the start method, which is a function in my DLL file, cannot be found in the path where my test code is located. I have tried to configure my properties as shown in this drescription, but as I said, I get this error. I will be very grateful if you can help me

class definition:

extern "C" class KWRAPPERTEIG_API K_WrapperTeigha_DXF_DWG
 {
  private:
     //create Data base
     OdDbDatabase* pDb;

     //tables
     OdDbLinetypeTablePtr    w_kOdLinetypeTablePtr;
     OdDbLayerTablePtr       w_kOdLayerTablePtr;
     OdDbTextStyleTablePtr   w_kOdTextStyleTablePtr;
     OdDbBlockTablePtr       w_kOdBlockTablePtr;

     OdDbBlockTableRecordPtr     w_kOdModelSpaceBlockRecPtr;
     //OdDbTextStyleTableRecordPtr pTextStyle;
 public:
     OdDb::DwgVersion     m_OdDwgVersion;    // Dwg/Dxf Version
     OdDb::SaveType       m_OdSaveType;      // DWG oder DXF




 public:
     K_WrapperTeigha_DXF_DWG();
     ~K_WrapperTeigha_DXF_DWG();

     void Start();
  }

macros:

#ifdef KWRAPPERTEIG_EXPORTS
#define KWRAPPERTEIG_API __declspec(dllexport)
#ifndef KWRAPPERTEIG__DLL
    #define KWRAPPERTEIG__DLL
#endif
#else
#define KWRAPPERTEIG_API __declspec(dllimport)
#endif
Zac Boussaid
  • 35
  • 1
  • 8
  • Have you tried extern "C" in making DLL? – K.R.Park Feb 21 '22 at 09:38
  • Are all the functions/classes exported properly? – kiner_shah Feb 21 '22 at 09:45
  • yes i tried but nothing changed – Zac Boussaid Feb 21 '22 at 09:46
  • @kiner_shah what you mean with properly i can show you i picture how i exported my classes – Zac Boussaid Feb 21 '22 at 09:47
  • By properly I meant, you didn't miss exporting something which is required to interface with the library. BTW I am just stating some possibilities I can think of. If you say that every required function/class is exported, then it's a different issue maybe. – kiner_shah Feb 21 '22 at 09:49
  • [![enter image description here][2]][2] [2]: https://i.stack.imgur.com/i20Yg.png – Zac Boussaid Feb 21 '22 at 09:50
  • @kiner_shah in the picture below you can see how i exported my class, the method start() is a fuction in my class "KWRAPPERTEIG_API" – Zac Boussaid Feb 21 '22 at 09:52
  • `KWRAPPERTEIG_API` looks like a macro name. What is it's expansion? BTW, can you edit the question, update and add necessary details there? – kiner_shah Feb 21 '22 at 09:54
  • @kiner_shah yes it's a macro and it was defined like this: [![enter image description here][3]][3] [3]: https://i.stack.imgur.com/lKiMY.png – Zac Boussaid Feb 21 '22 at 09:56
  • Kindly don't post images. Rather edit the question and copy/paste the code there. – kiner_shah Feb 21 '22 at 09:57
  • 1
    sorry @kiner_shah ok I'll do it – Zac Boussaid Feb 21 '22 at 09:58
  • OK, the problem seems to be that you are directly using `extern "C"` with a class. As per this link: https://stackoverflow.com/questions/17575060/c-dll-to-be-used-in-c-program, you need to create separate functions for interfacing with C code. – kiner_shah Feb 21 '22 at 10:02
  • BTW do you really need to interface this library with a C executable? – kiner_shah Feb 21 '22 at 10:07
  • @kiner_shah no, not really. It was suggested by K.R.Park and i thought it may help me to solve the problem – Zac Boussaid Feb 21 '22 at 10:25
  • You can remove the `extern "C"` then. Also for your problem, based on my little experience working on Windows, I remember that there are two files: DLL file containing binary of the library code and LIB file containing exported symbol information. Read [this](https://stackoverflow.com/a/913744/4688321). Can you check if both these files are generated? If yes, then please check if the include paths, library paths (path to LIB file) and library name is correct in the project settings of the project generating the executable. – kiner_shah Feb 21 '22 at 11:00
  • both files were generated in my project. But strangely, when I export functions/classes/etc. from the DLL, the compiler does not recognize the existence of the function or class in my DLL. I'll keep checking my paths because I'm pretty sure that's the reason. One last question: let's say the function I want to export contains an implicit error that the compiler doesn't recognize when it's created. is it possible in this case to get a export error like the one i have or not ? – Zac Boussaid Feb 21 '22 at 11:42
  • This [document](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170) explains how to use and create a DLL, I don't understand your other question, it stands to reason that the compiler will detect all errors. – Yujian Yao - MSFT Feb 22 '22 at 03:13

2 Answers2

1

This essentially means that your macro KWRAPPERTEIG_API was not correctly defined. It should have expanded to __declspec(dllexport) in order for the class functions to be exported.

extern "C" is supposed to turn of name mangling of functions, so they can be used by C. That can work, because C understands functions, just not overloaded functions. But C doesn't understand classes or class methods, so that it a bit pointless there. You can see that Start@K_WrapperTeigha_DXF_DWG@@QAEXXZ is still mangled.

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

@YujianYao-MSFT & Kiner_shah I really appreciate your help. I have solved the problem. My problem was that I created the dll file on Friday and then got the idea to change the location of creating the dll file and forgot about it. Then on Monday I copied the old file which does not contain my start() method. So the problem was the wrong parameterization of the dll file setting.

Zac Boussaid
  • 35
  • 1
  • 8