|
Yes! So simple! Thanks a lot!
|
|
|
|
|
I have a COM component with no .h files.But I want to use it,how should I begin?
Thanks.
GOOD LUCK
|
|
|
|
|
|
I am sorry that,I only have a .dll file of the COM component.
Thanks
|
|
|
|
|
#import is meant for such situations. NOTE: NOT #include but #import . Look it up!
Steve
|
|
|
|
|
|
He there,
I wrote a DLL in which i have got a function that shall be passed some data and a filename and it shall save the data into the file.
I tried three diffeent ways and at all off the three I get the message that I am not allowed to write to the file ("Access denied").
The first way I tried:
FILE *File;<br />
File = fopen("strName", "w+");<br />
fprintf(File, "Test");<br />
fflush(File);<br />
fclose(File);
The message comes when I reach the fflush line, when i delete it, the message comes at the fclose line.
The second way:
CFile FileHF;<br />
FileHF.Open(strName, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);<br />
FileHF.Write(pHF, sizeof(pHF));<br />
FileHF.Close();
This is the way i found around the internet told as working, not with me I get the message in the File.Write line.
The third way:
CFile FileHF;<br />
FileHF.Open(strName, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);<br />
CArchive ar(&FileHF, CArchive::store);<br />
ar << (int)pHF;
This way I found in a book, but here I get the Message in the CArchive line.
I am out of knowledge and ut of sources which could tell me the right way. Could you please?
thx
Lars
|
|
|
|
|
TheInfernalCrow wrote: I am not allowed to write to the file ("Access denied").
From where this access denied message got?
- NS -
|
|
|
|
|
Is this working in the application ? What i mean is are you getting this message only in dll ?
If you are getting it in both application and dll, may be you have not proper access rights.
|
|
|
|
|
I get a MessageBox saying that,
Both in Dll and my Prog I get the Message.
I am an Admin user in my system.
|
|
|
|
|
FILE *File;
File = fopen("strName", "w+");
fprintf(File, "Test");
fflush(File);
fclose(File);
this is your above code.
try removing '"' quotations before the strName and see.
then also if you are getting an error,
then hardcode the filename and see like fopen("c:\\test.txt");
and also you have to do some error checking like,
FILE *File;
File = fopen(strName, "w");//NOTE:try removing the + and see
if(File != NULL)
{
fprintf(File, "Test");
fflush(File);
fclose(File);
}
else
{
AfxMessageBox("File Not Opened successfully");
}
i suspect that, the problem may be with + or the filename you are passing.
|
|
|
|
|
i removed them and nothing changed as well only to have "w" in the fopen and hardcoding the filename
|
|
|
|
|
try doing the error checking as i did and post your code.
|
|
|
|
|
You can remove both the fflush and fclose statements.
The file will still generated and the text will be written in it.
Tell me the status, if you are still getting the error message, or the file is generating or not.
Also you can use ProcessExplorer to get the parent of the Error Message window. Is this the same application.
|
|
|
|
|
No I can't.
I get an empty file, nothing more.
|
|
|
|
|
For verification, first you check whether the file is existing or not. If existing make sure that the file does not have the read-only attributes (or system attribute).
- NS -
|
|
|
|
|
Are you using Vista?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi everybody! I have a question.
If there are two mouses(A,B) pluged in a computer, I wonder how to distinguish A from B.
plz help me
|
|
|
|
|
Are you able to use two mice at a same time???
Sreedhar DV
[Real success is having courage to meet failure without being defeated.]
|
|
|
|
|
To answer your question Sreedhar, yes, case in point laptops which come with a stupid touchpad which remains active when I plugin a respectable USB mouse.
To answer Charles, the only way you can do this is to use the Raw Input Model. Handle the WM_INPUT message, process the RAWINPUT structure pointed to by lParam, it contains a RAWINPUTHEADER structure which contains a hDevice that you can pass to GetRawInputDeviceInfo. NOTE: raw input is available only when the application calls RegisterRawInputDevices with valid device specifications.
|
|
|
|
|
Howdy guys,
I joined the forums several days after spending several more days exploring through all the wonderful articles posted here. I had started to teach myself c++ just about 2 months ago. Things go well at times and things go slow, I am sure you can relate to how it was starting how in the programming world.
Right now I have been trying to teach myself how to get a simple connection between two computers. My original plan was to build a basic chat client that acts as a server/client for a peer to peer type of connection. After some problems I have decided to make a very simple console server that listens on a port and prints a string that it receives.
My server listens in a port and it appears I can even make my client have an "ESTABLISHED" connection with my server. However when I send() and recv() data, nothing happends. Or it locks up.
I am concerned that I am not using the right sockets for the right job. What I guess I want is a very general clarification of what each socket will do. I have read through 4 different tutorials here and most have been extremely helpful, however due to my own incompitance I keep getting it wrong!
Right now the way I understand it.
The serverside will have two sockets.
a ListeningSocket
a ClientSocket
WIth the listeningsocket I create the socket.
ListeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
Bind the socket to a port and address
addr.sin_addr.s_addr = can be "INADDR_ANY" because its the server and is not targeted to connect at anything,
I bind port 8888, set the IP family type then run the BIND command
bind( ListeningSocket, (const sockaddr *)&addr, sizeof( SOCKADDR_IN ) );
using my SOCKADDR_IN struct to pass information to bind and what not
Then I listen
listen(ListeningSocket,10);
Now here I get somewhat confused
What socket does the accepting?
Right now I have setup the ClientSocket to accept the ListeningSocket
ClientSocket = accept(ListeningSocket, (sockaddr*)&addr, &len);
Is this backwards? Should I have it the otherway around with the ListeningSocket as the lhand value and accept ClientSocket? Many tutorials are pretty vague on this.
Then on the actual client side, I simply create one socket and attempt to connect to the server.
What I have now has appeared to give me a connection according to NETSTAT, however when I send() data nothing happends.
Perhaps my recv loop is setup incorrectly.
Any one have any advice? I hope my question was not to entirely vague, or another good tutorial I could follow along through. The more basic the tutorial the better!
Any help is truely appreciated!
Cliff
|
|
|
|
|
Make sure you get in the habit of checking return codes from the socket APIs.
For basic blocking sockets, your server should work ok.
accept() will block until a connection is available so if your app is a GUI app
your UI will stop responding unless the accept() call is not on the UI thread.
accept() returns a new socket, connected to the client. That's the socket you
should be receiving on. The listening socket returns to a listening state.
Make sure you set ports in the SOCKADDR_IN structs using network byte order.
What does your send code look like?
What does your "recv loop" code look like?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark I went through and rearranged all my code to output the WSAGetLastError() msg so I could then look it up. I rebuilt two programs, just simple console programs in this manner, one acting as a server, other a client.
I sent a simple char array "Hello" and vuala it worked! The error codes were a great idea, I suppose in programming I should be more responsible and use those codes! I found out one of my sockets were not being built correctly, my client socket on the server side because of the error. Once I figured it out I fired up my server and sent a message with my client. Boom it showed up on the server end. I'm so happy it works! I can finally see how it all functions now. The server side waits after the connection has been accepted to receive data.
I was afraid I would have to drop recv() in some kind of infinite loop in order to catch incoming data but I guess not! It waits untill data is received or the connection is terminated before processing any code below it! Now that I got that outa the way I can fix the code in my windows based client/server and go from there!
Thanks for the help Mark!
Cliff
|
|
|
|
|
Beaon wrote: I was afraid I would have to drop recv() in some kind of infinite loop in order to catch incoming data but I guess not!
Hi Cliff,
Note that there's a common beginner mistake with sockets when using send() and recv()
on a stream socket (like TCP).
recv() won't necessarily receive all the bytes you request. Even if a thousand bytes are
sent, only one byte could be received in a single recv() call but the call is considered successful.
That means you still have to loop calling recv() until you get the number of bytes you are expecting
or until an error occurs or the other end disconnects.
Another important reason for checking the return values
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks.
So does that entitle having my cient send() send the amount of bytes as a primary transmission? That way the receiving end knows that it should expect X number of bytes before finishing?
Thanks again for the help Mark it goes a long ways!
|
|
|
|