PDA

View Full Version : سوال: فراخوانی یک dll



python_85
دوشنبه 31 خرداد 1389, 14:21 عصر
سلام
من تو Qt یه dll درست کردم که می خوام تو ویژال سی فراخونی بکنمش
تو سایت دیدم که چه جوری یه dll رو میشه فراخونی کرد


bool CallMyDLL()
{
//WCHAR path="Socket.dll");
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibraryA("Socket.dll");
//LoadLibrary()
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"write");
/*
Define the Function in the DLL for reuse. This is just prototyping the dll's function.
A mock of it. Use "stdcall" for maximum compatibility.
*/
typedefbool (__stdcall * pICFUNC)(char *);
pICFUNC MyFunction;
MyFunction = pICFUNC(lpfnGetProcessID);
/* The actual call to the function contained in the dll */
bool MyReturnVal = MyFunction("hello");
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
/* The return val from the dll */
return MyReturnVal;
}

این هم کد فایل dll:


#include "socket.h"

Socket::Socket(QObject *parent)
{
soc=new QUdpSocket(parent);

}
bool Socket::write(char *Data)
{
QByteArray datagram ;
datagram.append(Data);
soc->writeDatagram(datagram.data(), datagram.size(),
QHostAddress::Broadcast, 45454);
return true;
}

bool Socket::read()
{
soc->bind(45454);
this->start();
return true;
}
void Socket::run()
{
while (soc->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(soc->pendingDatagramSize());
soc->readDatagram(datagram.data(), datagram.size());
ReciveData=datagram.data();
//statusLabel->setText(tr("Received datagram: \"%1\"")
// .arg(datagram.data()));
}
}
QString Socket::GetData()
{
return ReciveData;
}




برنامه ای که تو ویژوال سی نوشتم رو دیباگ که می کنم فکر می کنم می تونه dll رو لود کنه ولی جایی که می خواد تابع write رو فراخونی کنه برنامه خطا می ده(انگار null هست)
اگه لطف کنید راهنمایی کنید ممنون میشم