I am new to Vs and DLL project creation. After gone throught the MS dll creation website, started to create the dll for my application.
I have attached .h and source cpp file. I could able to create the dll but coundnt find the exported function in dependency viewer of the created dll.
I am currently having no idea in resolving this error. Some insights would be helpful in taking forward this.
Thanks in advance!
header file
#pragma once
#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif
#include <cstdint>
#include <cstddef>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
using namespace cv;
struct BoundingBox {
std::array<uint32_t, 2> top_left;
std::array<uint32_t, 2> bottom_right;
BoundingBox(std::array<uint32_t, 2> top_left, std::array<uint32_t, 2> bottom_right)
: top_left(top_left), bottom_right(bottom_right) {}
std::string to_string() const {
return "top left: " + std::to_string(top_left[0]) + ", " + std::to_string(top_left[1]) + ", bottom right: " + std::to_string(bottom_right[0]) + ", " + std::to_string(bottom_right[1]);
}
};
struct ADROutput {
BoundingBox bounding_box;
float score;
int class_id;
ADROutput(int class_id, float score, std::array<std::array<uint32_t, 2>, 2> bounding_box)
: bounding_box(BoundingBox(bounding_box[0], bounding_box[1])), score(score), class_id(class_id) {}
std::string to_string() const {
return "Class_id: " + std::to_string(class_id) + ", Confidence: " + std::to_string(score) + ", Bounding Box: " + bounding_box.to_string();
}
};
struct Detection {
BoundingBox bounding_box;
float score;
int class_id;
};
// Define ProcessFrameOutput structure
typedef struct ProcessFrameOutput {
uint32_t size;
ADROutput* detections;
} ProcessFrameOutput;
enum class Mode : int {
Default = 1,
};
struct DetectorConfig {
std::string model_path;
std::string device;
double iou_threshold;
double score_threshold;
// Constructor
DetectorConfig(std::string model_path, std::string device, double iou_thresh, double score_thresh)
: model_path(model_path), device(device), iou_threshold(iou_thresh), score_threshold(score_thresh) {}
// Default constructor
DetectorConfig() : model_path(""), device("CPU"), iou_threshold(0.45), score_threshold(0.7) {}
// Function to get weights path
std::string weights_path() {
return model_path + ".bin";
}
};
struct ADRConfig {
DetectorConfig detector_config;
};
class ModeAlgorithm {
public:
virtual std::vector<ADROutput> process_frame(const cv::Mat& frame) = 0;
virtual void reset() = 0;
};
class ADR : public ModeAlgorithm {
private:
DetectorConfig detector;
ADRConfig config;
public:
ADR() {}
std::vector<ADROutput> process_frame(const cv::Mat & frame) {
std::vector<Detection> detections;
std::vector<ADROutput> outputs;
return outputs;
}
void reset() {
//debug("Reset called - TBD implement detector reset to intialization state when needed - processing with current config: {}", config.detector_config);
}
};
struct YoloADR {
ModeAlgorithm* adr_var;
YoloADR(Mode mode) {
switch (mode) {
case Mode::Default:
adr_var = new ADR();
break;
}
}
std::vector<ADROutput> process_frame(const Mat& frame) {
return adr_var->process_frame(frame);
}
void reset() {
adr_var->reset();
}
};
extern "C" __declspec(dllexport) YoloADR * gpa_initialize(Mode mode);
extern "C" __declspec(dllexport) bool gpa_process_frame(YoloADR* adr, uint32_t frame_rows, uint32_t frame_cols, uint32_t frame_stride, void* frame_data, ProcessFrameOutput* detections_out);
extern "C" __declspec(dllexport) void gpa_drop_detections(ProcessFrameOutput* detections);
extern "C" __declspec(dllexport) bool gpa_reset(YoloADR* adr);
extern "C" __declspec(dllexport) bool gpa_close(YoloADR* adr);
extern "C" __declspec(dllexport) void pritnline();
Source cpp file
type here#include <windows.h>
#include <opencv2/opencv.hpp>.
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
#include <memory>
#include <cstring>
#include "pch.h"
#include "gpa_interface.h"
using namespace cv;
YoloADR * gpa_initialize(Mode mode) {
// logger::setup_logging();
// debug("Initialize gpa called with mode ", mode);
return new YoloADR(mode);
}
template<typename T>
void check_for_null_pointer(T* pointer) {
if (pointer == nullptr) {
throw std::runtime_error(std::string(typeid(T).name()) + " pointer is null");
}
}
bool gpa_process_frame(YoloADR * adr,uint32_t frame_rows,uint32_t frame_cols,uint32_t frame_stride,void* frame_data,ProcessFrameOutput * detections_out)
{
// debug("Process frame called");
Mat frame(frame_rows, frame_cols, CV_8UC4, frame_data, frame_stride);
Mat formatted_frame;
cvtColor(frame, formatted_frame, COLOR_RGBA2BGR, 3);
std::vector<ADROutput> detection = adr->process_frame(formatted_frame);
ADROutput* detection_ptr = detection.data();
uint32_t size = detection.size();
ProcessFrameOutput output = {
output.size = size,
output.detections = detection_ptr
};
std::memcpy(detections_out, &output, sizeof(ProcessFrameOutput));
return true;
}
void gpa_drop_detections(ProcessFrameOutput * detections) {
if (detections == nullptr) {
return;
}
delete[] detections->detections;
}
bool gpa_reset(YoloADR * adr) {
adr->reset();
return true;
}
bool gpa_close(YoloADR * adr)
{
try {
//debug("Close called");
check_for_null_pointer(adr);
delete adr;
return true;
}
catch (...) {
return false;
}
}
void pritnline()
{
std::cout << "print" << std::endl;
}