开发者

C++ DLL creation for C# project - No functions exported

开发者 https://www.devze.com 2022-12-23 13:00 出处:网络
I am working on a project that requires some image processing. The front end of the program is C# (cause the guys thought it is a lot simpler to make the UI in it). However, as the image processing pa

I am working on a project that requires some image processing. The front end of the program is C# (cause the guys thought it is a lot simpler to make the UI in it). However, as the image processing part needs a lot of CPU juice I am making this part in C++.

The idea is to link it to the C# project and just call a function from a DLL to make the image processing part and allow to the C# environment to process the data afterwards. Now the only problem is that it seems I am not able to make the DLL. Simply put the compiler refuses to put any function into the DLL that I compile.

Because the project requires some development time testing I have created two projects into a C++ solution. One is for the Dll and another console application. The console project holds all the files and I just include the corresponding header into my DLL project file. I thought the compiler should take out the functions that I marked as to be exported and make the DLL from them. Nevertheless this does not happens.

Here it is how I defined the function in the header:

extern "C" __declspec(dllexport)  void _stdcall RobotData(BYTE* buf, int** pToNewBackgroundImage, int* pToBackgroundImage,  bool InitFlag, ObjectInformation* robot1, ObjectInformation* robot2,   ObjectInformation* robot3, ObjectInformation* robot4,  ObjectInformation* puck);

extern "C" __declspec(dllexport)  CvPoint _stdcall RefPointFinder(IplImage* imgInput, CvRect &imgROI, 
                         CvScalar &refHSVColorLow, CvScalar &refHSVColorHi );

Followed by the implementation in the cpp file:

extern "C" __declspec(dllexport)  CvPoint _stdcall RefPointFinder(IplImage* imgInput, CvRect  &imgROI,&refHSVColorLow, CvScalar &refHSVColorHi ) { \\...
                  return cvPoint((int)( M10/M00) +  imgROI.x, (int)( M01/M00 ) +  imgROI.y) ;}

extern "C" __declspec(dllexport)  void _stdcall RobotData(BYTE* buf, int** pToNewBackgroundImage, int* pToBackgroundImage,  bool InitFlag, ObjectInformation* robot1, ObjectInformation* robot2,   ObjectInformation* robot3, ObjectInformation* robot4,  ObjectInformation* puck) { \\ ...};

And my main file for the DLL project looks like:

#ifdef _MANAGED
#pragma managed(push, off)
#endif

/// <summary开发者_StackOverflow社区> Include files.  </summary>
#include "..\ImageProcessingDebug\ImageProcessingTest.h"
#include "..\ImageProcessingDebug\ImageProcessing.h"


BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
 return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

Needless to say it does not work. A quick look with DLL export viewer 1.36 reveals that no function is inside the library. I don't get it. What I am doing wrong ?

C++ DLL creation for C# project - No functions exported

As side not I am using the C++ objects (and here it is the C++ DLL part) such as the vector. However, only for internal usage. These will not appear in the headers of either function as you can observe from the previous code snippets.

Any ideas? Thx,

Bernat


It seems you are confused about which files to include in your DLL project vs your console project. If it is true that "The console project holds all the files" then this is your problem.

Your DLL project needs to include the cpp file which has the __declspec(dllexport)s. As you describe it, you have included your RefPointFinder() & RobotData() functions in the console project. In other words your DLL has no functions in it whatsoever, regardless of whether anything is exported.

Just including the .h files in the DLL main file does nothing by itself. It doesn't include these functions in the DLL.

0

精彩评论

暂无评论...
验证码 换一张
取 消