问题
I've built an example project from the Amazon IoT Device SDK which is the PubSub Sample project from the examples folder.
I've had to output the project as a DLL file so that the sample can be used in RAD studio, which I have been able to build successfully. Using the tutorials from generating a DLL, I've added in the __declspec(dllexport) line to the function definitions in the class.
PubSub.hpp file
#ifdef PUBSNUB_EXPORTS
#define PUBSNUB_API __declspec(dllexport)
#else
#define PUBSNUB_API __declspec(dllimport)
#endif
#include "mqtt/Client.hpp"
#include "NetworkConnection.hpp"
namespace awsiotsdk {
namespace samples {
class PubSub {
protected:
std::shared_ptr<NetworkConnection> p_network_connection_;
std::shared_ptr<mqtt::ConnectPacket> p_connect_packet_;
std::atomic_int cur_pending_messages_;
std::atomic_int total_published_messages_;
std::shared_ptr<MqttClient> p_iot_client_;
__declspec(dllexport) ResponseCode RunPublish(int msg_count);
__declspec(dllexport) ResponseCode SubscribeCallback(util::String topic_name,
util::String payload,
std::shared_ptr<mqtt::SubscriptionHandlerContextData> p_app_handler_data);
__declspec(dllexport) ResponseCode DisconnectCallback(util::String topic_name,
std::shared_ptr<DisconnectCallbackContextData> p_app_handler_data);
__declspec(dllexport) ResponseCode ReconnectCallback(util::String client_id,
std::shared_ptr<ReconnectCallbackContextData> p_app_handler_data,
ResponseCode reconnect_result);
__declspec(dllexport) ResponseCode ResubscribeCallback(util::String client_id,
std::shared_ptr<ResubscribeCallbackContextData> p_app_handler_data,
ResponseCode resubscribe_result);
__declspec(dllexport) ResponseCode Subscribe();
__declspec(dllexport) ResponseCode Unsubscribe();
__declspec(dllexport) ResponseCode InitializeTLS();
public:
__declspec(dllexport) ResponseCode RunSample();
};
}
}
I'm stuck on not knowing how to call the RunSample() in an example Console project as an example to make sure that my DLL file is working properly. I've tried calling the function directly but it's saying it's undefined.
#include <iostream>
#include "PubSub.hpp"
int main()
{
RunSample();
}
来源:https://stackoverflow.com/questions/59645685/calling-a-class-defined-function-from-a-dll-file-c