|
Include windows.h and link with kernel32.lib. From there you can call the function just like any other.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks so much for your quick reply. How do I "link with kernel32.lib"?
Khang
|
|
|
|
|
Depending on the type of project created, I would suspect that kernel32.lib is linked in by default. If not, just add it to the linker options like any other library.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Dear all,
i am recently working on a project using DirectX 8.1 and VC++.NET. I need to develop the program under fullscreen mode. Then i realize i need to add a printing function, to call the printers connected and print some documents and pictures in the program. I have some knowledge on how to do it using MFC, but not under the circumstance i described above.
So i welcome the nice gentlemen who know this trick enlighten me abit. thank you very much in advance.
cheers
stan
The man of tomorrow is shaped by his battles today.
|
|
|
|
|
This is just a guess but I would think that printing is printing regardless of what is happening on/with the screen. Is that not true?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
thanks, David. I'm trying various means to solve it. =)
|
|
|
|
|
Does anyone have the source code of an audio decoder and encoder?
I want to encode the sound of a TV capture card and then send it through internt to the client which then decode and play the sound.
Really Thanks a lot for your kind help!!~
|
|
|
|
|
Hi. I'm trying to create a C++ class with a const static member variable of type valarray, but i do not know how to declare and initialize it. Can anyone help me?
|
|
|
|
|
class foo
{
public:
static const std::valarray < int > m_array;
};
const std::valarray< int > foo::m_array(-1, 5);
int main(int argc, char* argv[])
{
for (int i=0;i<5;i++)
{
printf("%d,", foo::m_array[i]);
}
return 0;
}
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Thanks for your answer. Two more questions...:
1) I'm trying to define a non static valarray member, stores 15 elements of type double, but without success. All help i found defines valarrays within main(). I tried the same definitions for my class but dose not work. Actually i tried:
class myClass
{
private:
std::valarray<double> m_array;
}
With this the compiler is ok, but when i tryied to asing values to m_array with [] operator, program crashes (actually this is logical because the m_array is of size 1, i think...).
class myClass
{
private:
std::valarray<double> m_array(15);
}
VC++ 2003 comliler generates the following error :
error C2059: syntax error : 'constant'
2) The valarray allocates memory dynamically on the heap or statically? So if i want a huge valarray (say 10000 elements) is this ok:
std::valarray<double> hugeArray(10000);
or i have to allocate the valarray dynamically using a pointer?
Thanks again.
|
|
|
|
|
for #1, you can use C++'s "initialization list" feature on your constructor:
#include < valarray >
class myClass
{
public:
myClass() : m_array(15)
{
}
private:
std::valarray< double > m_array;
};
you can add simple constructor 'calls' to your member ojects right to your own objects c'tor. very handy.
for #2, the elements are allocated dynamically by the valarray's ctor, via the "new" operator.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Thanks again. That was very helpfull for me.
while(living)
{
i'm learning;
}
|
|
|
|
|
I am having a problem with CFileDialog. Have a look at this code:
CString strFirst = "C:\\1.txt";
CString strSecond = "C:\\aa\\1.txt";
CopyFile(strFirst, strSecond, FALSE);
This code is simply copying a file 1.txt to a folder named aa present at C root. After I do this and I try to delete folder aa(while my application is still running), it lets me delete it and that's OK. Now have a look at the problem code:
CFileDialog dlg(false);
CString strPathName;
if(dlg.DoModal() == IDOK)
{
strPathName = dlg.GetPathName();
CopyFile(strFirst, strPathName, FALSE);
}
Now, if I select the same folder in CFileDialog and create a file there, it copies it quite well thru CopyFile function. The problem is that If I try to delete folder aa now (with my application still open), it wont let me delete it although I can delete the newly created file inside this folder but deletion of folder is not possible. It gives an error message saying that this folder is in use by some other program.
Am I doing something wrong or is it a bug in CFileDialog. I think it is a bug. Looks like CFileDialog is not releasing the handle of the folder. What is your opinion.
I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
My Articles
|
|
|
|
|
Sometimes CFileDialog will switch directories.
You can call GetCurrentDirectory to see if it has switched to the directory the first file is in (the file you can not delete).
Also, I think it has a slow release cache built into the dialog or some code it utilitizes. If you were to wait a moment, you would find you might be able to delete the files. I say this because, if you watch your debug output after calling a CFileDialog, you will notice information about a secondary thread you did not directly create that terminates after a few seconds. This might be where the caching is occurring. I don't know how to force it to flush immediately.
I think it is a 'design feature' of CFileDialog that can sometimes get in your way.
|
|
|
|
|
What about:
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
What about:
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR);
That doesn't help. This can be reproduced even with this.
CFileDialog dlg(false);
dlg.DoModal();
When Dialog appears, You dont even need to switch the directory. Just enter any filename and then u will not be able to delete that directory. I am stuck here....
I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
My Articles
|
|
|
|
|
This works fine for me:
CFileDialog dlg(FALSE);
dlg.m_ofn.Flags |= OFN_NOCHANGEDIR;
if (dlg.DoModal() == IDOK)
{
CString strPath = dlg.GetPathName();
CopyFile("c:\\somefile.txt", strPath, FALSE);
} Whether I create the folder through Explorer or via CFileDialog , I can remove the folder while the application is running.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanx David, that worked. I was thinking on wrong lines I guess. I thought that OFN_ENABLEHOOK was creating some sort of problem bcoz it was hooking it with a global method and the scope of that global method was program-level. So, I was trying to play with OFN_ENABLEHOOK flag and that was not helping.
Anyways, thanx a lot again.
I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
My Articles
|
|
|
|
|
I had developed the client program under Visual C++ 6.0. I use the Windows socket programming. I compile and build my program using the Win32 Console application.There is no errors and warnings. But after I executing the program, I found that if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ... <datan>\n",argv[0]);
exit(1);
}
the output is usage: %s <server> <data1> <data2> ... <datan> and stop with executing the rest of the program.My work is to send data to the server PC which is under the Linux environment.
The following is my program:Thanks for helping.
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#define SERVER_PORT 1500
#define MAX_MSG 100
//int CreatFile(char *szServer, short nPort);
//*CreatFile();
int main (int argc, char *argv[]) {
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;
//
// Initialize WinSock and check the version
//
nRet = WSAStartup(wVersionRequested, &wsaData);
if (wsaData.wVersion != wVersionRequested)
{
fprintf(stderr,"\n Wrong version\n");
return 0;
}
int sd, rc, i;
struct sockaddr_in localAddr, servAddr;
struct hostent *h;
if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ... <datan>\n",argv[0]);
exit(1);
}
// The gethostbyname() function is used when we have the DNS name of our server
h = gethostbyname(argv[1]);
if(h==NULL) {
printf("%s: unknown host '%s'\n",argv[0],argv[1]);
exit(1);
}
//
// Fill in the address structure
//
servAddr.sin_family = h->h_addrtype;
memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
servAddr.sin_port = htons(SERVER_PORT);
/* create socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd<0) {
perror("cannot open socket ");
exit(1);
}
/* bind any port number */
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(0);
rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr));
if(rc<0) {
printf("%s: cannot bind port TCP %u\n",argv[0],SERVER_PORT);
perror("error ");
exit(1);
}
/* connect to server */
rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));
if(rc<0) {
perror("cannot connect ");
exit(1);
}
for(i=2;i
|
|
|
|
|
I had developed the client program under Visual C++ 6.0. I use the Windows socket programming. I compile and build my program using the Win32 Console application.There is no errors and warnings. But after I executing the program, I found that if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ... <datan>\n",argv[0]);
exit(1);
}
the output is usage: %s <server> <data1> <data2> ... <datan> and stop with executing the rest of the program.My work is to send data to the server PC which is under the Linux environment.
The following is my program:Thanks for helping.
#include <stdio.h>
#include <winsock.h>
#include <windows.h>
#define SERVER_PORT 1500
#define MAX_MSG 100
//int CreatFile(char *szServer, short nPort);
//*CreatFile();
int main (int argc, char *argv[]) {
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;
//
// Initialize WinSock and check the version
//
nRet = WSAStartup(wVersionRequested, &wsaData);
if (wsaData.wVersion != wVersionRequested)
{
fprintf(stderr,"\n Wrong version\n");
return 0;
}
int sd, rc, i;
struct sockaddr_in localAddr, servAddr;
struct hostent *h;
if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ... <datan>\n",argv[0]);
exit(1);
}
// The gethostbyname() function is used when we have the DNS name of our server
h = gethostbyname(argv[1]);
if(h==NULL) {
printf("%s: unknown host '%s'\n",argv[0],argv[1]);
exit(1);
}
//
// Fill in the address structure
//
servAddr.sin_family = h->h_addrtype;
memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
servAddr.sin_port = htons(SERVER_PORT);
/* create socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd<0) {
perror("cannot open socket ");
exit(1);
}
/* bind any port number */
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(0);
rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr));
if(rc<0) {
printf("%s: cannot bind port TCP %u\n",argv[0],SERVER_PORT);
perror("error ");
exit(1);
}
/* connect to server */
rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr));
if(rc<0) {
perror("cannot connect ");
exit(1);
}
for(i=2;i
|
|
|
|
|
So does this reproduce the problem:
int main( int argc, char *argv[] )
{
if (argc < 3)
{
printf("usage: %s ... \n", argv[0]);
exit(1);
}
return 0;
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks for your reply. Now I try to execute this program to send the the data to the Linux computer server which using the BSD socket.Can I doing this just on the console application mode in VC++6.0 without doing the graphical User interface first? What of the steps of doing this?
Anyway, can I know why is its execution stop at usage: %s ... without doing the send()command?
Hoping for your help.Thank you.
|
|
|
|
|
yanyu81 wrote:
Anyway, can I know why is its execution stop at usage: %s ... without doing the send()command?
Because that's the way you've written the code. If you do not want it to stop, you must remove the call to exit() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Question1:
After I remove all the exit(), I found that the output becomes
"usage: %s ... "
cannot connect:No error
Press any key to continue_
How can I fix this code to execute the whole program?
Question2: Can I just execute this program in the Win32 Console Application under the VC++6.0 to send the data to the Linux computer server which using the BSD socket.Can I doing this just on the console application mode in VC++6.0 without doing the graphical User interface first?Like using DOS to type the location of the executable file? What of the steps of doing this?
Thanks.
|
|
|
|
|
If the printf() statement is being called, it's because the if condition that precedes it is evaluating to true.
When sending data via sockets, it matters not what the interface is. Whether it's a console application or a GUI application, those are merely for the user's benefit, not the programs.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|