|
|
Yes, but it requires some roundabout work. The gyst of is is that the EXE should create a batch file that tries to delete that EXE file and then itself, and then the EXE should shut down. The batch file then will be able to delete the EXE file. (Note that batch files have the unique ability to delete themselves.)
The batch file would be something along the lines of this (please excuse any syntax errors!)
rem First, delete the EXE. It will be in use unti
rem it quits, so keep trying until we succeed.
:label
DEL myfile.exe
if exist myfile.exe goto label
rem Now delete this batch file
delete %0.bat
There is an MSDN article about it - I can't recall it right now, but some searching will probably find it.
An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.
|
|
|
|
|
cool! thanks!!
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
HOW CAN I CONVERT VISUAL C++ DLL(a DLL which writed in visual C++) TO BORLAND DLL?THEN I WANT TO COMPILE IT.. PLEASE HELP ME.
gurk@n
|
|
|
|
|
If it's just standard C++, just open it with the Borland IDE and recompile.
If you're using MFC/VC++ stuff, bad luck.
|
|
|
|
|
Hi there,
I would like to build a piece of sw that creates a virtual serial port, establishes a tcp connection with a server and forwards everything that is written in the virtual serial port to the server and vice versa.
Could you please give some hints/direction on how I can do that, especially the first part?
Thank you in advance,
Nikos Nikolaou
|
|
|
|
|
Hi !
The whole solution is to design, write and register a so-called pseudo-device driver. Pseudo-devices are software components that the Windows system recognizes as devices, but which require no actual hardware to exist.
When the driver is registered and running, you can open a handle to it (CreateFile) and use ReadFile/WriteFile calls to send and receive data from it. Because a serial communications device supports overlapped I/O, you can also use event objects to request signals from the operating system when an event occurs. The easiest way to understand an event object is to think of a hardware interrupt. Waiting for an event object to signal is very much like waiting for an interrupt to trigger.
The device itself, when created, must use the Windows Sockets API to create a socket connection to the specified server. Then it can start serving the application by responding to ReadFile/WriteFile calls appropriately.
To give you a nice & handy head-start, you should see David Dunlop's article 'Introduction to Device Drivers'. The article can be found here[^]. In this article, he will help you through the process of creating and registering a pseudo-device driver that does not do anything.
For a more in-depth look, go read mjtsai's article here[^]. Follow the article through, and fill in the necessary code for your pseudo-device to
a) identify itself as a serial communications device (AddDevice-call)
b) create and connect the socket when a handle is opened (IRP_MJ_CREATE)
c) offer data transfer services to/from the socket (IRP_MJ_READ/IRP_MJ_WRITE)
d) close the socket when a handle is closed (IRP_MJ_CLOSE)
As you can see, I have named the different events to which your pseudo-device driver needs to respond. The type of device you wish to represent is called 'FILE_DEVICE_SERIAL_PORT'. This information is given during the IoCreateDevice call.
For more information on how device drivers work, I suggest buying a good book. Programming the Windows Driver Model, 2nd Edition is one of the best I can recommend. But I hope this answer will get you started.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Dear Antti,
Thank you for the info. Is there a specific socket API that can be used from driver-code, or the win2sock API is ok?
Nikos
|
|
|
|
|
The Windows Sockets 2 API is just fine. Remember to link with the libraries and triple-check your code for performance/logical errors. A driver program is running in the kernel mode, and a mistake/crash in there is fatal to the operating system. A thorough checking and simulation of all possible error states must be done.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I've included winsock2.h, but the compiler complains about syntax errors in winbase.h
Any hints;
Nikos
|
|
|
|
|
Without knowing any more precise information about the error itself it's pretty difficult to help you out.
Because having an actual syntax error in the Platform SDK is quite unprobable, I would suggest that you double-check the source code files you have. Try compiling the project without the Winsock header. Try adding the necessary Windows version definitions before including any header files from the Platform SDK. For information about the version defines, see 'Using the SDK Headers'.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi,
I want to convert an IP address(dotted quad)...to a number. Can someone tell me how to do this?? I believe it can be converted to a unsigned long. Once converted how can it be converted back to the original dotted quad format??
Thanks.
Jerry
|
|
|
|
|
Assuming an IP address in the form a.b.c.d
This will work on a 32bit machine with unsigned long as 32 bits and char as 8bits.
typedef union
{
unsigned long nIPAddressAsNumber;
struct
{
unsigned char a;
unsigned char b;
unsigned char c;
unsigned char d;
} dotted;
} IPAddressUnion;
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Try these functions from Winsock2.h
inet_addr - converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the IN_ADDR structure. (unsigned long)
and
inet_ntoa - converts an (Ipv4) Internet network address into a string in Internet standard dotted format
|
|
|
|
|
I'm trying to get a raw packet sent out on XP SP1. Supposedly, I should be able to do this on SP2 also (I'm not trying to spoof the source) but I have SP1 installed.
I'm using the following code to create the socket:
sd = WSASocket(AF_INET, SOCK_RAW,IPPROTO_RAW, 0, 0, 0);<br />
if (sd == INVALID_SOCKET) {<br />
cerr << "Failed to create raw socket: " << WSAGetLastError() <<<br />
endl;<br />
return -1;<br />
}
What happens is an ARP request is sent, then the packet is sent but the Ethernet header is generated by the OS. I shouldn't even see the ARP request if I'm truly using raw sockets. The exact same thing happens when I run this on Win98 so something's missing - I just don't know what.
Searches on google, ... turn up hundreds of pages of debate on the SP2 issue but nothing that I could find in terms of examples of how to use the XP raw sockets.
Any help would be greatly appreciated.
Thanks,
Dave
|
|
|
|
|
The answer is probably in the AF_INET family. As stated in the MSDN documentation under "TCP/IP Raw Sockets", it is said that
Note The Microsoft implementation of TCP/IP on Windows is capable of opening a raw UDP socket.
As the AF_INET family specifies the TCP/IP family, this note might mean that because WSASocket asks the service provider to create a socket that supports the required parameters, it will create a raw UDP socket. UDP packets include the Ethernet header, so that would explain why the header is generated. As for the ARP request that I can't explain.
Dunno how close to truth this is, as I haven't needed any raw sockets myself.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
HI
I am new to MFC VC++. I want to creat a Button control in VC++. I created cMyButton class derived from CButton.
I want that if i move the cursor on the button, it should display some text in one of the static controls on my Dlg.
is there a way to pass the pointer of the static control to the cMyButton class.
I added some code like this:
CStatic m_static;
cMyButton::SetStaticCtrl(CStatic &cstatic)
{
m_static = cstatic;
}
void cMyButton::OnMouseMove(UINT nFlags, CPoint point)
{
m_static->SetWindowText("This is test! OK");
CButton::OnMouseMove(nFlags, point);
}
But above code gives errors. Pl. ((help me solving this.
Tell me how to access controls on Dialog from CButton derived classes.
|
|
|
|
|
as you said you want to pass the pointer, however you pass the static control by reference and then copy it...
make your m_static member of CMyButton a pointer like:
CStatic *m_pStatCtrl;
make your SetStaticCtrl like:
void CMyButton::SetStaticCtrl(CStatic* pStatCtrl)
{
m_pStatCtrl = pStatCtrl;
}
and finally you onmousemove should look like
if( NULL != m_pStatCtrl )
m_pStatCtrl->SetWindowText(... );
//and here the rest of the func...
It would be good to set you m_pStatCtrl pointer to NULL in the constructor of CMyButton just as a precaution..
hope this helps you...
Greetings,
Davy
|
|
|
|
|
Hi
Thanks a lot for your help.
Its working for me.
|
|
|
|
|
Howdy -
I have a fully qualified PIDL (i.e. LPITEMIDLIST struct), and I am completely at a loss as to how to get the parent (fully qualified) PIDL from it?
Any thoughts?
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
|
Hi Guys,
I have a question. I have many Documents with data, and i want to draw the graphics of all of them in just one view. but i cannot find a solution yet. Any suggestions?
|
|
|
|
|
|
I know this is simple to most users but I am new at this.
I want to close down a dialog screen as soon as as an option to open another
dialog (using a button), so that I am only left with certain screens and not
access to all dialog screens.
Many thanx,
Phil
|
|
|
|
|
For each window use it's own DestroyWindow() function.
|
|
|
|