标签:pac cer led set produce either class name warning
//---------------------------------------------------------
// AVEXE.CPP
// Compile options needed: /GX
#pragma warning (disable : 4786)
#include <map>
#include <string>
#include <stdio.h>
__declspec(dllimport)
std::map<int,std::string>* GiveMeAMap(int n);
__declspec(dllimport)
void ShowMeTheMap(std::map<int,std::string> *amap);
__declspec(dllexport)
const char* MapItemX (std::map<int,std::string> *m, int x);
int main () {
// Create the map in the DLL
int x = 6;
std::map<int,std::string> *p = GiveMeAMap(x);
// Display the contents of the map from the DLL
printf("Showing contents from the DLL\n");
ShowMeTheMap(p);
// Display the contents of the map from the EXE
// using the accessor function from the DLL so we
// aren‘t directly accessing the map
printf("Showing contents from the EXE using accessor\n");
int i = x;
while (i--) {
printf("%d = %s\n",i,MapItemX(p,i));
}
// Access Violation when accessing the map that
// was created in the DLL from the EXE
printf("Showing contents from the EXE directly\n");
while (x--) {
printf("%d = %s\n",x,(*p)[x].c_str());
}
return 0;
}
//---------------------------------------------------------
// AVDLL.CPP
// Compile options needed /GX
#pragma warning (disable : 4786)
#include <map>
#include <string>
#include <stdlib.h>
// Create the map here in the DLL
__declspec(dllexport)
std::map<int,std::string>* GiveMeAMap(int n) {
std::map<int,std::string> *m = new std::map<int,std::string>;
while(n--) {
char b[33];
itoa(n,b,2);
(*m)[n] = std::string(b);
}
return m;
}
// We can access the map without error from the executable
// image where the map was created
__declspec(dllexport)
void ShowMeTheMap(std::map<int,std::string> *p) {
int x = p->size();
while (x--) {
printf("%d = %s\n",x,(*p)[x].c_str());
}
}
// An accessor method to return the associated C string
// for key x
__declspec(dllexport)
const char* MapItemX (std::map<int,std::string> *m, int x) {
return (*m)[x].c_str();
}
Article ID: 172396 - Last Review: Sep 2, 2005 - Revision: 1
标签:pac cer led set produce either class name warning
原文地址:http://www.cnblogs.com/gushandujian/p/7300964.html