Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: patilanz en 16 Agosto 2015, 06:08 am



Título: DLL con STL (vector,string,stringstream) exportar
Publicado por: patilanz en 16 Agosto 2015, 06:08 am
Hola tengo una DLL que exporta esta función:

Código
  1. //Al principio era: vector<string> split(string str,char c);
  2. void split(string str, char c,vector<string>* strings){
  3. stringstream stream(str);
  4. string item;
  5. while (getline(stream, item, c)){
  6. strings->push_back(item);
  7. }
  8. }
  9.  

Luego:
Código
  1. HMODULE lib = LoadLibrary("C:\\Users\\Dimitar\\Documents\\Visual Studio 2013\\Projects\\BasicTools\\Release\\BasicTools.dll");
  2. if (lib == NULL){
  3. e("Library failed to load!");
  4. }
  5. _split split = (_split)GetProcAddress(lib, "split");
  6. if (!split){
  7. e("Failed to load split!");
  8. }
  9. string test = "Hola me llamo Jose!";
  10. vector<string> strings;
  11. split(test, ' ', &strings);
  12. for (auto str : strings){
  13. cout << str << endl;
  14. }

Recibo error por alocar memoria, me lo esperaba...
Hay alguna manera de exportar vector y string?

Un saludo


Título: Re: DLL con STL (vector,string,stringstream) exportar
Publicado por: ivancea96 en 16 Agosto 2015, 13:27 pm
Alocar xD *reservar*

¿Con vector<string> split(string str,char c); te da problemas?


Título: Re: DLL con STL (vector,string,stringstream) exportar
Publicado por: patilanz en 16 Agosto 2015, 17:46 pm
Alocar xD *reservar*

¿Con vector<string> split(string str,char c); te da problemas?

Reservar, oops xD
Código
  1. vector<string> split(string str, char c){
  2. vector<string> strings;
  3. stringstream stream(str);
  4. string item;
  5. while (getline(stream, item, c)){
  6. strings.push_back(item);
  7. }
  8. return strings;
  9. }
  10.  
Código
  1. typedef vector<string>(*_split)(string,char);
  2. //...
  3. vector<string> strings = split(test, ' ');

Error: 0xC0000005: Infracción de acceso al leer la ubicación 0x0111EFFC.


Título: Re: DLL con STL (vector,string,stringstream) exportar
Publicado por: BlackZeroX en 22 Agosto 2015, 22:26 pm
No lo se quizas si...

Código
  1. vector<string> strings = new vector<string>();

Saludos!¡.