PDA

Visualizza la versione completa : [C++]Importare dll


Luc@s
29-05-2003, 18:04
Ho il seguente cod:

#include <iostream>
#include <cstdio>
#include <windows.h>

HMODULE hModule = LoadLibrary("Engine.dll");
bool __stdcall (*op)( string );

using namespace std;

int main()
{
op = ( bool __stdcall ( * )( string ) ) GetProcAddress( hModule, "Open" );
if( op("prova.txt") == true)
{
cout << "Ok!\n"<<endl;
}else
{
cout << "No!\n"<<endl;
}
return 0;
}

Ma mi da:


C:/Documents and Settings/Admin/Desktop/Edit/Teck Edit/Src/Test/Test.cpp:6: `
string' was not declared in this scope
C:/Documents and Settings/Admin/Desktop/Edit/Teck Edit/Src/Test/Test.cpp:6: warning: `
__stdcall__' attribute only applies to function types
C:/Documents and Settings/Admin/Desktop/Edit/Teck Edit/Src/Test/Test.cpp: In
function `int main()':
C:/Documents and Settings/Admin/Desktop/Edit/Teck Edit/Src/Test/Test.cpp:12: cannot
convert `bool (*)(std::basic_string<char, std::char_traits<char>,
std::allocator<char> >)' to `bool*' in assignment
C:/Documents and Settings/Admin/Desktop/Edit/Teck Edit/Src/Test/Test.cpp:13: `
op' cannot be used as a function

Esecuzione terminata

$$$
29-05-2003, 18:59
#include <iostream>
#include <cstdio>
#include <windows.h>
using namespace std;

typedef bool (__stdcall * OPENFUNC) (string);

int main()
{
HMODULE hModule = LoadLibrary("Engine.dll");
if (hModule)
{
OPENFUNC op = (OPENFUNC) GetProcAddress(hModule, "Open" );

if( op("prova.txt") )
cout << "Ok!\n";
else
cout << "No!\n";
} else
cout << "Dll non trovata!\n";


return 0;
}


io non userei la classe string, ma dei semplici puntotori ad array di caratteri null-terminati :-|

Luc@s
29-05-2003, 19:05
tnk x l'aiuto

Loading