A
acoder1983
why the code fails
composed of two projects(compiled by VC6)
Test.dll (Test.h, Test.cpp)
Main.exe (Main.cpp)dependent by Test.dll
Test.dll
//----------------------------------------------------
// Test.h
#pragma once
#ifdef TEST_EXPORTS
#define TEST_API __declspec(dllexport)
#else
#define TEST_API __declspec(dllimport)
#endif
#include "Test.h"
#include <vector>
using namespace std;
class TEST_API Test
{
public:
void PushInts(vector<int>& vec, int num);
};
TEST_API void PushInts2(vector<int>& vec, int num);
//-----------------------------------------------------
//-----------------------------------------------------
// Test.cpp
#define TEST_EXPORTS
#include <windows.h>
#include "Test.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void Test:ushInts(vector<int>& vec, int num)
{
vec.push_back(num);
}
void PushInts2(vector<int>& vec, int num)
{
vec.push_back(num);
}
//-----------------------------------------------------
Main.exe
//-----------------------------------------------------
#include "Test.h"
int main(int argc, char* argv[])
{
vector<int> vec;
Test t;
t.PushInts(vec, 1);
return 0;
}
//-----------------------------------------------------
composed of two projects(compiled by VC6)
Test.dll (Test.h, Test.cpp)
Main.exe (Main.cpp)dependent by Test.dll
Test.dll
//----------------------------------------------------
// Test.h
#pragma once
#ifdef TEST_EXPORTS
#define TEST_API __declspec(dllexport)
#else
#define TEST_API __declspec(dllimport)
#endif
#include "Test.h"
#include <vector>
using namespace std;
class TEST_API Test
{
public:
void PushInts(vector<int>& vec, int num);
};
TEST_API void PushInts2(vector<int>& vec, int num);
//-----------------------------------------------------
//-----------------------------------------------------
// Test.cpp
#define TEST_EXPORTS
#include <windows.h>
#include "Test.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void Test:ushInts(vector<int>& vec, int num)
{
vec.push_back(num);
}
void PushInts2(vector<int>& vec, int num)
{
vec.push_back(num);
}
//-----------------------------------------------------
Main.exe
//-----------------------------------------------------
#include "Test.h"
int main(int argc, char* argv[])
{
vector<int> vec;
Test t;
t.PushInts(vec, 1);
return 0;
}
//-----------------------------------------------------