krydea
asked on
big problem..
hi all,
i what to make a exe with a dll in the exe not external or something...maybe i have to link it or put it in the resource file?
can someone plz tell me?
Carlos Smith
Ps: every thing is welcome and if i'm not clear just say it and i will try to explane it batter.
and i use borland delphi 5.0
i what to make a exe with a dll in the exe not external or something...maybe i have to link it or put it in the resource file?
can someone plz tell me?
Carlos Smith
Ps: every thing is welcome and if i'm not clear just say it and i will try to explane it batter.
and i use borland delphi 5.0
Hi krydea,
IF you just want to add the dll to your exe
and then extract them use this:
1. Use a text editor to create a *.rc file that describes the DLL
-------------------------- ---------- ------
MY_DLL DLLTEST "TEST.DLL"
-------------------------- ---------- ------
2. The first two parameters can be whatever you want.
They get used in your program later.
Then, use the BRCC32.EXE command line compiler that ships with Delphi
to create a *.res file.
If your file in step 1 was MYDLL.rc, the command from the DOS prompt would be:
BRCC32 MyFont
3. The program will append the .rc to the input, and create a file with the
same name except it appends .res: MyDll.res
In your program, add a compiler directive to include your newly created file:
-------------------------- ---------- ------
{$R MyFont.res}
-------------------------- ---------- ------
4. Here is the function to extract the DLL to a specifies directory:
-------------------------- ---------- -------
Procedure ExtractDLLTo(DLLPath, DLLName : String);
var
Res : TResourceStream;
begin
IF DLLPath[Length(DLLPath)] <> '\' then DLLPath := DLLPath + '\';
Res := TResourceStream.Create(hIn stance, 'MY_DLL', Pchar('DLLTEST'));
Res.SavetoFile(DLLPath + DLLName);
Res.Free;
End;
-------------------------- ---------- ---------- ------
GL
Bug
IF you just want to add the dll to your exe
and then extract them use this:
1. Use a text editor to create a *.rc file that describes the DLL
--------------------------
MY_DLL DLLTEST "TEST.DLL"
--------------------------
2. The first two parameters can be whatever you want.
They get used in your program later.
Then, use the BRCC32.EXE command line compiler that ships with Delphi
to create a *.res file.
If your file in step 1 was MYDLL.rc, the command from the DOS prompt would be:
BRCC32 MyFont
3. The program will append the .rc to the input, and create a file with the
same name except it appends .res: MyDll.res
In your program, add a compiler directive to include your newly created file:
--------------------------
{$R MyFont.res}
--------------------------
4. Here is the function to extract the DLL to a specifies directory:
--------------------------
Procedure ExtractDLLTo(DLLPath, DLLName : String);
var
Res : TResourceStream;
begin
IF DLLPath[Length(DLLPath)] <> '\' then DLLPath := DLLPath + '\';
Res := TResourceStream.Create(hIn
Res.SavetoFile(DLLPath + DLLName);
Res.Free;
End;
--------------------------
GL
Bug
ASKER
so like "BRCC32 MyFont bla.dll"
and the bla.dll will be added to the resource file?
and can't i just load it with out to extratct it?
and the bla.dll will be added to the resource file?
and can't i just load it with out to extratct it?
ASKER
or how will i create the rc file?
I'm not sure.
But i think no.
But i think no.
Just how u crate an txt-file and then save
it as *.rc
it as *.rc
ASKER
and how ill i create the rc file?
ASKER
can yopu make a *.bat file? os i can see what i have to type in dos..?
but then you must create the BAT-File!?!?
ASKER
i know but only to see witch parameters i have to give ad: BRCC32..
To create an rc file at dos prompt:
copy con test.rc
Then type:
MY_DLL TESTDLL "Test.dll"
Then press:
STRG+Z
A "^Z" will be displayed
Then press:
ENTER
"1 file(s) copied" will be displayed
copy con test.rc
Then type:
MY_DLL TESTDLL "Test.dll"
Then press:
STRG+Z
A "^Z" will be displayed
Then press:
ENTER
"1 file(s) copied" will be displayed
To compile a rc-file to a res-file:
BRCC32 NAME.RC
It will be create a the NAME.RES file
BRCC32 NAME.RC
It will be create a the NAME.RES file
ASKER
copy con (what is con) test.rc
MY_DLL TESTDLL "Test.dll"<- were in a txt file???
Then press:
STRG+Z
A "^Z" will be displayed
Then press:
ENTER
oke but were??
can't you else make a example project with a bat file that creat's a rc file?
MY_DLL TESTDLL "Test.dll"<- were in a txt file???
Then press:
STRG+Z
A "^Z" will be displayed
Then press:
ENTER
oke but were??
can't you else make a example project with a bat file that creat's a rc file?
//For ex.: CreateRCFILE('C:\', 'FILE.RC');
Procedure CreateRCFile(SaveTo, Name : String);
CONST
RCSTRING : STRING = 'MY_DLL DLLTEST "TEST.DLL"';
VAR
RCFile : TEXT;
Begin
IF SaveTo[Length(SaveTo)] <> '\' then SaveTo := SaveTo + '\';
AssignFile(RCFile, SaveTo + Name);
Rewrite(RCFILE);
Writeln(RCFILE, RCSTRING);
CloseFile(RCFILE);
End;
Procedure CreateRCFile(SaveTo, Name : String);
CONST
RCSTRING : STRING = 'MY_DLL DLLTEST "TEST.DLL"';
VAR
RCFile : TEXT;
Begin
IF SaveTo[Length(SaveTo)] <> '\' then SaveTo := SaveTo + '\';
AssignFile(RCFile, SaveTo + Name);
Rewrite(RCFILE);
Writeln(RCFILE, RCSTRING);
CloseFile(RCFILE);
End;
ASKER
make.bat
"path name of the exe\BRC32.EXE" -r maindll.rc
maindll.rc:
MY_DLL TESTDLL "Test.dll"
"path name of the exe\BRC32.EXE" -r maindll.rc
maindll.rc:
MY_DLL TESTDLL "Test.dll"
Do you know how make a plain text - file under windows?
ASKER
k,
now how to load teh dll/dll function..
now how to load teh dll/dll function..
ASKER
plaine text fiel under windows. it works i thing so contiun on the loading etc k?;-)
Is your dll written in DElphi or C?
ASKER
C
how did you know lol.
do ou what that i post it here?
how did you know lol.
do ou what that i post it here?
Here is the stuff to load a function from
a dll.
This will be my last comment for the next hours.
It is 01:10 and i'm going to bed now.
//DLL written in DELPHI
TYPE
TYourProcedure = Procedure(s : string);
TYourFunction = Function(s : string) : Integer;
{ OR }
//DLL written in C
TYourProcedure = Procedure(s : string);cdecl;
TYourFunction = Function(s : string) : Integer;cdecl;
VAR
YourProcedure : TYourProcedure;
YourFunction : TYOurFunction;
VAR
DLLHandle : THandle;
//DLLPath ex.: 'C:\test.dll'
Procedure INIT_DLL_FUNCTION(DLLPath : String);
Begin
DLLHandle := LoadLibrary(PCHar(DLLPATH) );
If @DLLHandle = nil then
ShowMessage('Initializatio n failed: Could not load "test.dll"');
YourProcedure := GetProcAddress(DLLHandle, 'MYPROCEDURE');
IF @YourProcedure = nil then
ShowMessage('Initializatio n failed: Could not init function "MYProcedure"');
YourFunction := GetProcAddress(DLLHandle, 'MYFUNCTION');
IF @YourFunction = nil then
ShowMessage('Initializatio n failed: Could not init function "MYFUNCTION"');
End;
Procedure GET_DLL_FREE;
Begin
FreeLibrary(DLLHandle);
End;
a dll.
This will be my last comment for the next hours.
It is 01:10 and i'm going to bed now.
//DLL written in DELPHI
TYPE
TYourProcedure = Procedure(s : string);
TYourFunction = Function(s : string) : Integer;
{ OR }
//DLL written in C
TYourProcedure = Procedure(s : string);cdecl;
TYourFunction = Function(s : string) : Integer;cdecl;
VAR
YourProcedure : TYourProcedure;
YourFunction : TYOurFunction;
VAR
DLLHandle : THandle;
//DLLPath ex.: 'C:\test.dll'
Procedure INIT_DLL_FUNCTION(DLLPath : String);
Begin
DLLHandle := LoadLibrary(PCHar(DLLPATH)
If @DLLHandle = nil then
ShowMessage('Initializatio
YourProcedure := GetProcAddress(DLLHandle, 'MYPROCEDURE');
IF @YourProcedure = nil then
ShowMessage('Initializatio
YourFunction := GetProcAddress(DLLHandle, 'MYFUNCTION');
IF @YourFunction = nil then
ShowMessage('Initializatio
End;
Procedure GET_DLL_FREE;
Begin
FreeLibrary(DLLHandle);
End;
ASKER
hey it's here 1:10 to are you dutch?
no, german
ASKER
this is what i made:
unit dll1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TWords = Array[0..10] of String;
TSocket = Function(i: integer ;s : Twords) : Integer;cdecl;
var
Form1 : TForm1;
Socket : TSocket;
Words : Twords;
DllHandle : THandle;
implementation
{$R *.DFM}
{$R maindll.RES}
Procedure ExtractDLLTo(DLLPath, DLLName : String);
var
Res : TResourceStream;
begin
IF DLLPath[Length(DLLPath)] <> '\' then DLLPath := DLLPath + '\';
Res := TResourceStream.Create(hIn stance, 'MY_DLL', Pchar('TESTDll'));
Res.SavetoFile(DLLPath + DLLName);
Res.Free;
End;
Procedure INIT_DLL_FUNCTION(DLLPath : String);
Begin
DLLHandle := LoadLibrary(PCHar(DLLPATH) );
If @DLLHandle = nil then
ShowMessage('Initializatio n failed: Could not load "maindll.dll"');
Socket := GetProcAddress(DLLHandle, 'main');
IF @Socket = nil then
ShowMessage('Initializatio n failed: Could not init function "main"');
End;
Procedure GET_DLL_FREE;
Begin
FreeLibrary(DLLHandle);
End;
procedure TForm1.Button1Click(Sender : TObject);
begin
Words[0]:='testdll.exe';
Words[1]:='127.0.0.1';
Words[2]:='c:\autoexec.bat ';
Socket(3,Words);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ExtractDLLTo('C:\' , 'maindll.dll');
INIT_DLL_FUNCTION('C:\main dll.dll');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
GET_DLL_FREE;
end;
procedure TForm1.Button2Click(Sender : TObject);
begin
Words[0]:='testdll.exe';
Words[1]:='127.0.0.1';
Words[2]:='-s';
Words[3]:='c:\autoexec.xxx xxx';
Socket(4,Words);
end;
end.
the loading goes fine the function to but the running not:(
umm her is my c/c++ dll i compiled it with vc 6.0:
///#define _MT // multithread for process.h
#include <windows.h>
#include <process.h>
//#include <winsock2.h>
//#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <acssvcc.h>
#include "myerror.h"
static int iProcAttaches;
INT WINAPI DllEntryPoint
(
HINSTANCE hInst,
ULONG ul_reason_being_called,
LPVOID lpReserved
)
{
switch (ul_reason_being_called)
{
case DLL_PROCESS_ATTACH:iProcAt taches++; break;
case DLL_THREAD_ATTACH:break;
case DLL_THREAD_DETACH:break;
case DLL_PROCESS_DETACH: break;
}
UNREFERENCED_PARAMETER(lpR eserved);
return 1;
}
////////////////////////// ////////// ////////// ////////// /////
void WaitForConnect(void* pParam);
void WaitForReceive(void* pParam);
char* ArgFile=NULL;
bool WillSnd=false;
bool InitReady=false;
bool CloseNow=false;
char str[260];
class CSocket
{
public:
CSocket()
{
Handle=INVALID_SOCKET;
Client=NULL;
Init=Server=Active=FALSE;
};
~CSocket(){};
BOOL Open(int af = AF_INET, int type = SOCK_STREAM, int protocol = 0)
{
if( !Init )
{
{
WSADATA WSAData;
if( WSAStartup(MAKEWORD(1,1), &WSAData) != 0 )return(FALSE);
}
Init=TRUE;
}
Handle=socket(af, type, protocol);
if( Handle == INVALID_SOCKET )return(FALSE);
return(TRUE);
}
BOOL Initialize(char* Address, WORD Port)
{
HOSTENT hAddress;
SOCKADDR_IN hSockAddr;
if( !FillAddress(Address, &hAddress) )return(FALSE);
memcpy((char FAR *)&(hSockAddr.sin_addr), hAddress.h_addr, hAddress.h_length);
hSockAddr.sin_family=AF_IN ET;
hSockAddr.sin_port=Port;
if( bind(Handle, (struct sockaddr FAR *)&hSockAddr, sizeof(hSockAddr)) ==
SOCKET_ERROR )
return(FALSE);
return(TRUE);
}
BOOL StartServer(char* Addr, WORD Port)
{
if( !Initialize(Addr, Port) )return(FALSE);
if( listen(Handle, 1) == SOCKET_ERROR )return(FALSE);
Server=Active=TRUE;
WaitThread=_beginthread(Wa itForConne ct, 0, (void* )this);
return(TRUE);
}
BOOL StartClient(char* Addr, WORD Port)
{
HOSTENT hAddress;
SOCKADDR_IN hSockAddr;
if( !FillAddress(Addr, &hAddress) )return(FALSE);
memcpy((char FAR *)&(hSockAddr.sin_addr), hAddress.h_addr, hAddress.h_length);
hSockAddr.sin_family=AF_IN ET;
hSockAddr.sin_port=Port;
if( connect(Handle, (struct sockaddr FAR *)&hSockAddr, sizeof(hSockAddr)) ==
SOCKET_ERROR )
return(FALSE);
WaitThread=_beginthread(Wa itForRecei ve, 0, (void* )this);
return(TRUE);
}
BOOL Close(void)
{
if( Client )closesocket(Client);
if( Handle )closesocket(Handle);
Client=Handle=0;
Init=Active=FALSE;
return(TRUE);
}
BOOL SendText(char* Text)
{
if( send(Handle, Text, strlen(Text)+1, MSG_DONTROUTE) != SOCKET_ERROR )
return(FALSE);
return(TRUE);
}
BOOL SendFile(char* Text)
{
FILE* File;
printf("\nSend: %s\n", Text);
File=fopen(Text, "rb");
if( !File )return(FALSE);
char Buffer[1024]="@";
send(Handle, Buffer, 1, MSG_DONTROUTE);
fseek(File, 0, SEEK_END);
long Size=ftell(File);
fseek(File, 0, SEEK_SET);
sprintf(Buffer, "%10.10ld", Size);
send(Handle, Buffer, 11, MSG_DONTROUTE);
int Len;
while( (Len=fread(Buffer, 1, 1024, File)) > 0 )
send(Handle, Buffer, Len, MSG_DONTROUTE);
fclose(File);
return(TRUE);
}
BOOL FillAddress(char* Address, HOSTENT* hAddress)
{
HOSTENT* p=gethostbyname(Address);
if( !p )
{Mbox(ErrorFunction()); return(FALSE);}
memcpy(hAddress, p, sizeof(HOSTENT));
return(TRUE);
}
PSTR ErrorFunction(char* Title = NULL)
{
int Error=WSAGetLastError();
char* Msg;
switch( Error )
{
case WSANOTINITIALISED:
Msg="A successful AfxSocketInit must occurbefore using this API."; break;
case WSAENETDOWN :
Msg="The Windows Sockets implementationdetected that the network "
"subsystem failed."; break;
case WSAEADDRINUSE: Msg="The specified address is already inuse."; break;
case WSAEINPROGRESS: Msg="A blocking Windows Sockets call is inprogress.";
break;
case WSAEADDRNOTAVAIL :
Msg="The specified address is not availablefrom the local machine."; break;
case WSAEAFNOSUPPORT :
Msg="Addresses in the specified familycannot be used with this socket.";
break;
case WSAECONNREFUSED: Msg="The attempt to connect was rejected.";break;
case WSAEDESTADDRREQ : Msg="A destination address is required.";break;
case WSAEFAULT: Msg="The nSockAddrLen argument isincorrect."; break;
case WSAEINVAL:Msg="The socket is not already bound to anaddress."; break;
case WSAEISCONN : Msg="The socket is already connected.";break;
case WSAEMFILE : Msg="No more file descriptors areavailable."; break;
case WSAENETUNREACH:
Msg="The network cannot be reached from thishost at this time."; break;
case WSAENOBUFS :
Msg="No buffer space is available. Thesocket cannot be connected."; break;
case WSAENOTSOCK : Msg="The descriptor is not a socket.";break;
case WSAETIMEDOUT :
Msg="Attempt to connect timed out withoutestablishing a connection."; break;
case WSAEWOULDBLOCK :
Msg="The socket is marked as nonblocking andthe connection cannot"
" be completed immediately."; break;
case WSAHOST_NOT_FOUND :Msg="Authoritative Answer Host not found.";
break;
case WSATRY_AGAIN:Msg="Non-Auth oritative Host not found, or server failure.";
break;
case WSANO_RECOVERY :Msg="Nonrecoverable error occurred.";
break;
case WSANO_DATA :Msg="Valid name, no data record of requested type.";
break;
case WSAEINTR :Msg="The (blocking) call was canceled through ";
break;
default : Msg="Unknown error."; break;
}// switch
if( Title )printf("\r\n%s\r\n%s\r\n" , Title, Msg);
else printf("\r\n%s\r\n", Msg);
CloseNow=true;
return Msg;
}//void ErrorFunction(char* Title = NULL) end
////////////////////////// ////////// ////////// ////////// ////////// /////
BOOL Init;
BOOL Server;
BOOL Active;
SOCKET Handle;
SOCKET Client;
unsigned long WaitThread;
};// class CSocket ends
////////////////////////// ////////// ////////// ////////// ////////// ////////// /////
void WaitForConnect(void* pParam)
{
CSocket* Socket=(CSocket* )pParam;
Socket->Client=accept(Sock et->Handle , NULL, NULL);
if( Socket->Client != INVALID_SOCKET )
{
printf("\r\nConnected\r\n" );
Socket->Server=FALSE;
closesocket(Socket->Handle );
Socket->Handle=Socket->Cli ent;
Socket->Client=0;
Socket->WaitThread=_begint hread(Wait ForReceive , 0, (void* )Socket);
}
else
{
printf("\r\nNot Connected\r\n");
Socket->Client=0;
Socket->WaitThread=NULL;
}
_endthread();
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
void WaitForReceive(void* pParam)
{
CSocket* Socket=(CSocket* )pParam;
if (!WillSnd)InitReady=true;
int Ret;
char Buffer;
while( (Ret=recv(Socket->Handle, &Buffer, 1, 0) != SOCKET_ERROR) && Ret )
{
if( Buffer == '@' ) // File
{
printf("\nRecieve: %s\n", ArgFile);
FILE* File;
long nSize, S;
char Size[11];
recv(Socket->Handle, Size, 11, 0);
S=nSize=atol(Size);
printf("File: %-10.10ld\r\n", nSize);
printf("%-10.10ld", 0l);
File=fopen(ArgFile, "wb");
while( nSize)
{
static char Buffer[1024]="";
long BuffSize=1024;
if( nSize < BuffSize )BuffSize=nSize;
BuffSize=recv(Socket->Hand le, Buffer, BuffSize, 0);
fwrite(Buffer, 1, BuffSize, File);
nSize-=BuffSize;
printf("\b\b\b\b\b\b\b\b\b \b");
printf("%-10.10ld", S-nSize);
}
fclose(File);
printf(" : OK\r\n");
CloseNow=true;
}// if
else if( Buffer == 'G' ) // Go send
{
InitReady=true;
}
}// while 1
CloseNow=true;
printf("\r\nNot Connected\r\n");
Socket->WaitThread=NULL;
_endthread();
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// //
int maino(int argc, char* argv[])
{
CSocket Socket;
char* ArgIP=NULL;
char* ArgSR=NULL;
if( argc == 4 )
{
ArgIP=argv[1];
ArgFile=argv[3];
WillSnd=true;
//printf("You will send the file %s to %s\n", ArgFile, ArgIP);
sprintf(str,"You will send the file %s to %s\n", ArgFile, ArgIP);
Mbox(str);
if( !Socket.Open() || !Socket.StartServer(ArgIP, 99) )
{
Mbox(Socket.ErrorFunction( ));
Socket.Close();
return 0;
}
else
//printf("\nPress Ctrl+C to exit\nWait...\n");
Mbox("Press Ctrl+C to exit");
while(1)
{
if (InitReady)
{
InitReady=false;
Mbox("Server Init Completed");
//printf("Server Init Completed\n");
if (Socket.SendFile(ArgFile))
{
printf("DONE\n");
}
else
{
printf("ERROR\n");
}
}
if (CloseNow)
{
if (Socket.Init)Socket.Close( );
return(1);
}
}// while ends
return(1);
}// if( argc == 4 ) ends
if( argc == 3 )
{
ArgIP=argv[1];
ArgFile=argv[2];
WillSnd=false;
printf("You will recieve a file from %s and will save it as %s\n"
, ArgIP, ArgFile);
if( !Socket.Open() || !Socket.StartClient(ArgIP, 99) )
{
Mbox(Socket.ErrorFunction( ));
}
else //printf("\r\nConnected\r\ nPress Q<enter> to exit\n");
{sprintf(str,"\r\nConnecte d\r\nPress Q<enter> to exit\n");
Mbox(str);
}
while(1)
{
if (InitReady)
{
InitReady=false;
printf("Client Init Completed\n");
Socket.SendText("G");
}
if (CloseNow)
{
if (Socket.Init)
Socket.Close();
return(1);
}
}// while(1)
return(1);
}// if( argc == 3 ) ends
printf("To send a file use:\n");
printf(" <program> ip -s filename\n");
printf("To recieve a file use:\n");
printf(" <program> ip filename\n");
return(0);
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// //
// /base:"0xBFB50000"
unit dll1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TWords = Array[0..10] of String;
TSocket = Function(i: integer ;s : Twords) : Integer;cdecl;
var
Form1 : TForm1;
Socket : TSocket;
Words : Twords;
DllHandle : THandle;
implementation
{$R *.DFM}
{$R maindll.RES}
Procedure ExtractDLLTo(DLLPath, DLLName : String);
var
Res : TResourceStream;
begin
IF DLLPath[Length(DLLPath)] <> '\' then DLLPath := DLLPath + '\';
Res := TResourceStream.Create(hIn
Res.SavetoFile(DLLPath + DLLName);
Res.Free;
End;
Procedure INIT_DLL_FUNCTION(DLLPath : String);
Begin
DLLHandle := LoadLibrary(PCHar(DLLPATH)
If @DLLHandle = nil then
ShowMessage('Initializatio
Socket := GetProcAddress(DLLHandle, 'main');
IF @Socket = nil then
ShowMessage('Initializatio
End;
Procedure GET_DLL_FREE;
Begin
FreeLibrary(DLLHandle);
End;
procedure TForm1.Button1Click(Sender
begin
Words[0]:='testdll.exe';
Words[1]:='127.0.0.1';
Words[2]:='c:\autoexec.bat
Socket(3,Words);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ExtractDLLTo('C:\' , 'maindll.dll');
INIT_DLL_FUNCTION('C:\main
end;
procedure TForm1.FormDestroy(Sender:
begin
GET_DLL_FREE;
end;
procedure TForm1.Button2Click(Sender
begin
Words[0]:='testdll.exe';
Words[1]:='127.0.0.1';
Words[2]:='-s';
Words[3]:='c:\autoexec.xxx
Socket(4,Words);
end;
end.
the loading goes fine the function to but the running not:(
umm her is my c/c++ dll i compiled it with vc 6.0:
///#define _MT // multithread for process.h
#include <windows.h>
#include <process.h>
//#include <winsock2.h>
//#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <acssvcc.h>
#include "myerror.h"
static int iProcAttaches;
INT WINAPI DllEntryPoint
(
HINSTANCE hInst,
ULONG ul_reason_being_called,
LPVOID lpReserved
)
{
switch (ul_reason_being_called)
{
case DLL_PROCESS_ATTACH:iProcAt
case DLL_THREAD_ATTACH:break;
case DLL_THREAD_DETACH:break;
case DLL_PROCESS_DETACH: break;
}
UNREFERENCED_PARAMETER(lpR
return 1;
}
//////////////////////////
void WaitForConnect(void* pParam);
void WaitForReceive(void* pParam);
char* ArgFile=NULL;
bool WillSnd=false;
bool InitReady=false;
bool CloseNow=false;
char str[260];
class CSocket
{
public:
CSocket()
{
Handle=INVALID_SOCKET;
Client=NULL;
Init=Server=Active=FALSE;
};
~CSocket(){};
BOOL Open(int af = AF_INET, int type = SOCK_STREAM, int protocol = 0)
{
if( !Init )
{
{
WSADATA WSAData;
if( WSAStartup(MAKEWORD(1,1), &WSAData) != 0 )return(FALSE);
}
Init=TRUE;
}
Handle=socket(af, type, protocol);
if( Handle == INVALID_SOCKET )return(FALSE);
return(TRUE);
}
BOOL Initialize(char* Address, WORD Port)
{
HOSTENT hAddress;
SOCKADDR_IN hSockAddr;
if( !FillAddress(Address, &hAddress) )return(FALSE);
memcpy((char FAR *)&(hSockAddr.sin_addr), hAddress.h_addr, hAddress.h_length);
hSockAddr.sin_family=AF_IN
hSockAddr.sin_port=Port;
if( bind(Handle, (struct sockaddr FAR *)&hSockAddr, sizeof(hSockAddr)) ==
SOCKET_ERROR )
return(FALSE);
return(TRUE);
}
BOOL StartServer(char* Addr, WORD Port)
{
if( !Initialize(Addr, Port) )return(FALSE);
if( listen(Handle, 1) == SOCKET_ERROR )return(FALSE);
Server=Active=TRUE;
WaitThread=_beginthread(Wa
return(TRUE);
}
BOOL StartClient(char* Addr, WORD Port)
{
HOSTENT hAddress;
SOCKADDR_IN hSockAddr;
if( !FillAddress(Addr, &hAddress) )return(FALSE);
memcpy((char FAR *)&(hSockAddr.sin_addr), hAddress.h_addr, hAddress.h_length);
hSockAddr.sin_family=AF_IN
hSockAddr.sin_port=Port;
if( connect(Handle, (struct sockaddr FAR *)&hSockAddr, sizeof(hSockAddr)) ==
SOCKET_ERROR )
return(FALSE);
WaitThread=_beginthread(Wa
return(TRUE);
}
BOOL Close(void)
{
if( Client )closesocket(Client);
if( Handle )closesocket(Handle);
Client=Handle=0;
Init=Active=FALSE;
return(TRUE);
}
BOOL SendText(char* Text)
{
if( send(Handle, Text, strlen(Text)+1, MSG_DONTROUTE) != SOCKET_ERROR )
return(FALSE);
return(TRUE);
}
BOOL SendFile(char* Text)
{
FILE* File;
printf("\nSend: %s\n", Text);
File=fopen(Text, "rb");
if( !File )return(FALSE);
char Buffer[1024]="@";
send(Handle, Buffer, 1, MSG_DONTROUTE);
fseek(File, 0, SEEK_END);
long Size=ftell(File);
fseek(File, 0, SEEK_SET);
sprintf(Buffer, "%10.10ld", Size);
send(Handle, Buffer, 11, MSG_DONTROUTE);
int Len;
while( (Len=fread(Buffer, 1, 1024, File)) > 0 )
send(Handle, Buffer, Len, MSG_DONTROUTE);
fclose(File);
return(TRUE);
}
BOOL FillAddress(char* Address, HOSTENT* hAddress)
{
HOSTENT* p=gethostbyname(Address);
if( !p )
{Mbox(ErrorFunction()); return(FALSE);}
memcpy(hAddress, p, sizeof(HOSTENT));
return(TRUE);
}
PSTR ErrorFunction(char* Title = NULL)
{
int Error=WSAGetLastError();
char* Msg;
switch( Error )
{
case WSANOTINITIALISED:
Msg="A successful AfxSocketInit must occurbefore using this API."; break;
case WSAENETDOWN :
Msg="The Windows Sockets implementationdetected that the network "
"subsystem failed."; break;
case WSAEADDRINUSE: Msg="The specified address is already inuse."; break;
case WSAEINPROGRESS: Msg="A blocking Windows Sockets call is inprogress.";
break;
case WSAEADDRNOTAVAIL :
Msg="The specified address is not availablefrom the local machine."; break;
case WSAEAFNOSUPPORT :
Msg="Addresses in the specified familycannot be used with this socket.";
break;
case WSAECONNREFUSED: Msg="The attempt to connect was rejected.";break;
case WSAEDESTADDRREQ : Msg="A destination address is required.";break;
case WSAEFAULT: Msg="The nSockAddrLen argument isincorrect."; break;
case WSAEINVAL:Msg="The socket is not already bound to anaddress."; break;
case WSAEISCONN : Msg="The socket is already connected.";break;
case WSAEMFILE : Msg="No more file descriptors areavailable."; break;
case WSAENETUNREACH:
Msg="The network cannot be reached from thishost at this time."; break;
case WSAENOBUFS :
Msg="No buffer space is available. Thesocket cannot be connected."; break;
case WSAENOTSOCK : Msg="The descriptor is not a socket.";break;
case WSAETIMEDOUT :
Msg="Attempt to connect timed out withoutestablishing a connection."; break;
case WSAEWOULDBLOCK :
Msg="The socket is marked as nonblocking andthe connection cannot"
" be completed immediately."; break;
case WSAHOST_NOT_FOUND :Msg="Authoritative Answer Host not found.";
break;
case WSATRY_AGAIN:Msg="Non-Auth
break;
case WSANO_RECOVERY :Msg="Nonrecoverable error occurred.";
break;
case WSANO_DATA :Msg="Valid name, no data record of requested type.";
break;
case WSAEINTR :Msg="The (blocking) call was canceled through ";
break;
default : Msg="Unknown error."; break;
}// switch
if( Title )printf("\r\n%s\r\n%s\r\n"
else printf("\r\n%s\r\n", Msg);
CloseNow=true;
return Msg;
}//void ErrorFunction(char* Title = NULL) end
//////////////////////////
BOOL Init;
BOOL Server;
BOOL Active;
SOCKET Handle;
SOCKET Client;
unsigned long WaitThread;
};// class CSocket ends
//////////////////////////
void WaitForConnect(void* pParam)
{
CSocket* Socket=(CSocket* )pParam;
Socket->Client=accept(Sock
if( Socket->Client != INVALID_SOCKET )
{
printf("\r\nConnected\r\n"
Socket->Server=FALSE;
closesocket(Socket->Handle
Socket->Handle=Socket->Cli
Socket->Client=0;
Socket->WaitThread=_begint
}
else
{
printf("\r\nNot Connected\r\n");
Socket->Client=0;
Socket->WaitThread=NULL;
}
_endthread();
}
//////////////////////////
void WaitForReceive(void* pParam)
{
CSocket* Socket=(CSocket* )pParam;
if (!WillSnd)InitReady=true;
int Ret;
char Buffer;
while( (Ret=recv(Socket->Handle, &Buffer, 1, 0) != SOCKET_ERROR) && Ret )
{
if( Buffer == '@' ) // File
{
printf("\nRecieve: %s\n", ArgFile);
FILE* File;
long nSize, S;
char Size[11];
recv(Socket->Handle, Size, 11, 0);
S=nSize=atol(Size);
printf("File: %-10.10ld\r\n", nSize);
printf("%-10.10ld", 0l);
File=fopen(ArgFile, "wb");
while( nSize)
{
static char Buffer[1024]="";
long BuffSize=1024;
if( nSize < BuffSize )BuffSize=nSize;
BuffSize=recv(Socket->Hand
fwrite(Buffer, 1, BuffSize, File);
nSize-=BuffSize;
printf("\b\b\b\b\b\b\b\b\b
printf("%-10.10ld", S-nSize);
}
fclose(File);
printf(" : OK\r\n");
CloseNow=true;
}// if
else if( Buffer == 'G' ) // Go send
{
InitReady=true;
}
}// while 1
CloseNow=true;
printf("\r\nNot Connected\r\n");
Socket->WaitThread=NULL;
_endthread();
}
//////////////////////////
int maino(int argc, char* argv[])
{
CSocket Socket;
char* ArgIP=NULL;
char* ArgSR=NULL;
if( argc == 4 )
{
ArgIP=argv[1];
ArgFile=argv[3];
WillSnd=true;
//printf("You will send the file %s to %s\n", ArgFile, ArgIP);
sprintf(str,"You will send the file %s to %s\n", ArgFile, ArgIP);
Mbox(str);
if( !Socket.Open() || !Socket.StartServer(ArgIP,
{
Mbox(Socket.ErrorFunction(
Socket.Close();
return 0;
}
else
//printf("\nPress Ctrl+C to exit\nWait...\n");
Mbox("Press Ctrl+C to exit");
while(1)
{
if (InitReady)
{
InitReady=false;
Mbox("Server Init Completed");
//printf("Server Init Completed\n");
if (Socket.SendFile(ArgFile))
{
printf("DONE\n");
}
else
{
printf("ERROR\n");
}
}
if (CloseNow)
{
if (Socket.Init)Socket.Close(
return(1);
}
}// while ends
return(1);
}// if( argc == 4 ) ends
if( argc == 3 )
{
ArgIP=argv[1];
ArgFile=argv[2];
WillSnd=false;
printf("You will recieve a file from %s and will save it as %s\n"
, ArgIP, ArgFile);
if( !Socket.Open() || !Socket.StartClient(ArgIP,
{
Mbox(Socket.ErrorFunction(
}
else //printf("\r\nConnected\r\
{sprintf(str,"\r\nConnecte
Mbox(str);
}
while(1)
{
if (InitReady)
{
InitReady=false;
printf("Client Init Completed\n");
Socket.SendText("G");
}
if (CloseNow)
{
if (Socket.Init)
Socket.Close();
return(1);
}
}// while(1)
return(1);
}// if( argc == 3 ) ends
printf("To send a file use:\n");
printf(" <program> ip -s filename\n");
printf("To recieve a file use:\n");
printf(" <program> ip filename\n");
return(0);
}
//////////////////////////
// /base:"0xBFB50000"
hi,
look at:
http://www.drbob42.com/delphi/headconv.htm
maybe this solve your problem.
I'm not sure.
But you load a function
from your c-dll called "main" and i only can
find, in your posted c source, a "maino" function
look at:
http://www.drbob42.com/delphi/headconv.htm
maybe this solve your problem.
I'm not sure.
But you load a function
from your c-dll called "main" and i only can
find, in your posted c source, a "maino" function
ASKER
yea i load it rong i did it now.. only one thing when he is in the function the complete app is frosen waiting for replay you can't do ennt thing.
ASKER
is there no function that not wait you utill the dll function is completly execute?
hi krydea,
try this code to wait until the function returns
VAR
_RDFResult : Integer;
ParamI : Integer;
ParamS : Word;
Function Test(i : integer; s : Word) : Integer;
Var
ThreadID : DWord;
ThreadHandle : Cardinal;
ThreadExCo : Cardinal;
Procedure _RunDLLFunction;
Begin
_RDFResult := Socket(ParamI, ParamS);
EndThread(0);
End;
Begin
ParamI := i;
ParamS := s;
//Thread runs immediately after creation
ThreadHandle := BeginThread(NIL, 0, @_RunDLLFunction, NIL, 0, ThreadID);
//Wait until Thread returns
Repeat
GetExitCodeThread(ThreadHa ndle, ThreadExCo);
Application.ProcessMessage s;
Until ThreadExCo = 0;
Result := _RDFResult;
end;
GL
Bug
try this code to wait until the function returns
VAR
_RDFResult : Integer;
ParamI : Integer;
ParamS : Word;
Function Test(i : integer; s : Word) : Integer;
Var
ThreadID : DWord;
ThreadHandle : Cardinal;
ThreadExCo : Cardinal;
Procedure _RunDLLFunction;
Begin
_RDFResult := Socket(ParamI, ParamS);
EndThread(0);
End;
Begin
ParamI := i;
ParamS := s;
//Thread runs immediately after creation
ThreadHandle := BeginThread(NIL, 0, @_RunDLLFunction, NIL, 0, ThreadID);
//Wait until Thread returns
Repeat
GetExitCodeThread(ThreadHa
Application.ProcessMessage
Until ThreadExCo = 0;
Result := _RDFResult;
end;
GL
Bug
ASKER
maybe you don't understand (i did not test the source).
when i run the dll function my app is frosen and is not even repainted util the dll function is done and i whant that is still happening and that i can press on button's etc.
do you understand?
when i run the dll function my app is frosen and is not even repainted util the dll function is done and i whant that is still happening and that i can press on button's etc.
do you understand?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanxthanxthanxthanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxv
it works.
maybe you thing i'm acting bit kiddy but i'm 14 so life with it;-) and i'm dutch;-)
it works.
maybe you thing i'm acting bit kiddy but i'm 14 so life with it;-) and i'm dutch;-)
ASKER
thanxthanxthanxthanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxthanxt hanxv
it works.
maybe you thing i'm acting bit kiddy but i'm 14 so life with it;-) and i'm dutch;-)
it works.
maybe you thing i'm acting bit kiddy but i'm 14 so life with it;-) and i'm dutch;-)
Do you just want compile the DLL to your exe-file?
Or do you want call functions from the DLL in your
exe-file, if the DLL is compiled to your exe-file?