|
|
Friends,
I want to read the data from Clip Board. what are the API's Avaialble for it in C++ . Can some one tel me Please.... Iam doing a Project on it ....
Thanks in Advance....
|
|
|
|
|
|
If you are doing a project on it, then your starting point should always be the MSDN reference[^], in order to get the basics of what is possible. I appreciate that MSDN is not always that easy to understand but you will at least learn the names of all the clipboard functions.
MVP 2010 - are they mad?
|
|
|
|
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STOP 0
#define TRUE 1
#define OK 1
#define FILE_NAME ("my.text")
typedef struct List
{
long lNum;
char cpsName[30];
long lCScore;
long lMathScore;
long atol(long i);
struct List *next;
}Stu;
Stu stuList[3] =
{
{1, "asd", 32, 44, 0},
{2, "ffg", 66, 66, 0},
{3, "dgd", 55, 44, 0},
};
Stu *CreateList()
{
Stu *head = NULL;
Stu *NewNode = NULL;
int i = 0;
for (i=0; i<3; i++)
{
NewNode = (Stu*)malloc(sizeof(Stu));
NewNode->lNum = stuList[i].atol(stuList[i].lNum);
strncpy(NewNode->cpsName, stuList[i].cpsName, 30);
NewNode->lCScore = stuList[i].atol(stuList[i].lCScore);
NewNode->lMathScore = stuList[i].atol(stuList[i].lMathScore);
NewNode->next = NULL;
if (NULL == head)
{
head = NewNode;
}
else
{
head->next = NewNode;
head = NewNode;
}
}
return head;
}
int SaveToFiles(Stu *head)
{
Stu *p = head;
FILE *fp;
char cFileName[1024] = {0};
if ((fp = fopen(FILE_NAME, "wb")) == NULL)
{
printf( "Open file error!\n" );
exit (1);
}
while (p != NULL)
{
if (fwrite(p, sizeof(Stu), 1, fp) == 1)
{
p = p->next;
}
else
{
printf("Write file error!\n");
exit(1);
}
}
fclose(fp);
printf( "Save file succeed!\n" );
return OK;
}
int OpenFiles()
{
char cFileName[256] = {0};
FILE *fp;
if (0 == (fp = fopen(FILE_NAME, "r")))
{
printf("Open file error!\n");
exit(0);
}
fgets(cFileName, 250, fp);
printf("%s", cFileName);
fclose(fp);
return OK;
}
int main()
{
Stu *head = NULL;
head = CreateList();
SaveToFiles(head);
OpenFiles();
return 0;
}
this is the error information:
error LNK2001: unresolved external symbol "public: long __thiscall List::atol(long)" (?atol@List@@QAEJJ@Z)
Debug/file.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
|
|
|
|
|
Firstly, do not repost the question, but edit the original.
As to the error you get the statement long atol(long i); in your structure is not defined anywhere. You cannot declare a method in a structure without implementing it. You should add your own atol() method, or simply call the default library function. Also as I stated earlier your CreateList() function also has a problem.
MVP 2010 - are they mad?
|
|
|
|
|
Yeah!
fist, Createlist()function has a problem ?why?could you give me a detail!
second, I know atol()is libiary but if I use like this it also has a problem,why?
thank you for your reply!
|
|
|
|
|
wbgxx wrote: I know atol()is libiary but if I use like this it also has a problem,why?
Sentences like this are rising to the top of the list of most useless statements. If your program does not work in some way, saying "it has a problem", gives us no information to guess what may be wrong. Please try and explain what happens; do you get a compiler error, does it cause an exception, does it return the wrong result, etc?
However, having looked at the code again I see:
NewNode->lNum = stuList[i].atol(stuList[i].lNum);
OK, so let's correct it
NewNode->lNum = atol(stuList[i].lNum);
The atol() function takes a string of digits as input and returns its value as a long variable. Your statement is trying to pass a long as its input parameter which a) is wrong, and b) makes no sense; the value is already a long .
The other problem with Createlist() is that it returns the pointer to the last structure in your list rather than the first; you need to keep a copy of the first entry added to the head pointer.
MVP 2010 - are they mad?
|
|
|
|
|
Oh!Yes,I see!
very grateful for you !
|
|
|
|
|
(2) Simple - if atol is a library function then use it as such!!
declare your struct like this:
typedef struct List
{
long lNum;
char cpsName[30];
long lCScore;
long lMathScore;
struct List *next;
}Stu;
And use the function like this:
NewNode->lCScore = stuList[i].atol(stuList[i].lCScore);
NewNode->lCScore = atol(stuList[i].lCScore);
|
|
|
|
|
enhzflep wrote: NewNode->lCScore = atol(stuList[i].lCScore);
Except that stuList[i].lCScore is already a long; as I pointed out in my previous message.
MVP 2010 - are they mad?
|
|
|
|
|
Yes indeed. 
|
|
|
|
|
Wish I had a £1 for every time I've done something similar
MVP 2010 - are they mad?
|
|
|
|
|
Hello everyone,
I am extremly new to vc++ 6.0 programming and i need to create a drag drop control that would draw an image or say a shape into my window.Can you people please tell me how should i start and where to start from.Name of class or may be library should help.
Thank you in advance.
|
|
|
|
|
hi ,I'm a freshman ,and newer to study c !this is my program!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STOP 0
#define TRUE 1
#define OK 1
#define FILE_NAME ("my.text")
typedef struct List
{
long lNum;
char cpsName[30];
long lCScore;
long lMathScore;
long atol(long i);
struct List *next;
}Stu;
Stu stuList[3] =
{
{1, "asd", 32, 44, 0},
{2, "ffg", 66, 66, 0},
{3, "dgd", 55, 44, 0},
};
Stu *CreateList()
{
Stu *head = NULL;
Stu *NewNode = NULL;
int i = 0;
for (i=0; i<3; i++)
{
NewNode = (Stu*)malloc(sizeof(Stu));
NewNode->lNum = stuList[i].atol(stuList[i].lNum);
strncpy(NewNode->cpsName, stuList[i].cpsName, 30);
NewNode->lCScore = stuList[i].atol(stuList[i].lCScore);
NewNode->lMathScore = stuList[i].atol(stuList[i].lMathScore);
NewNode->next = NULL;
if (NULL == head)
{
head = NewNode;
}
else
{
head->next = NewNode;
head = NewNode;
}
}
return head;
}
int SaveToFiles(Stu *head)
{
Stu *p = head;
FILE *fp;
char cFileName[1024] = {0};
//strcpy(cFileName, FILE_NAME);
if ((fp = fopen(FILE_NAME, "wb")) == NULL)
{
printf( "Open file error!\n" );
exit (1);
}
while (p != NULL)
{
if (fwrite(p, sizeof(Stu), 1, fp) == 1)
{
p = p->next;
}
else
{
printf("Write file error!\n");
exit(1);
}
}
//fputs(p, cFileName);
fclose(fp);
printf( "Save file succeed!\n" );
return OK;
}
int OpenFiles()
{
char cFileName[256] = {0};
FILE *fp;
if (0 == (fp = fopen(FILE_NAME, "r")))
{
printf("Open file error!\n");
exit(0);
}
fgets(cFileName, 250, fp);
printf("%s", cFileName);
fclose(fp);
return OK;
}
int main()
{
Stu *head = NULL;
head = CreateList();
SaveToFiles(head);
OpenFiles();
//Print(head);
return 0;
}
|
|
|
|
|
Please read the posting guidelines[^]. For instance, format your code properly using the code tag (otherwise, it is not readable).
Furthermore, you didn't ask any question and you didn't provide any description of the problem you encounter.
|
|
|
|
|
In addition to Cedric's good advice, you should review the CreateList() function, to see what it actually returns.
MVP 2010 - are they mad?
|
|
|
|
|
Hello!
In my MFC programm on Visual C++ 2008 i have the following problem with opening a file for reading:
-------------------------------------------
1) First step i do is to unzip a existing file (sSourceFile) containing my data with CZipArchive
Here to simplify matters without exception handling:
CZipArchive ZipArchive;
ZipArchive.Open(sSourceFile, CZipArchive::zipOpenReadOnly);
for (int i = 0; i < ZipArchive.GetCount(); i++)
{
ZipArchive.SetPassword(key);
ZipArchive.ExtractFile(i, GetProgramPath()); // GetProgramPath() is a own method which returns the current path
}
ZipArchive.Close();
-------------------------------------------
2) After that i rename the unzipped file:
DeleteFile(sTargetFile);
CFile::Rename( sSourceFile, sTargetFile ); // both, sSourceFile and sTargetFile, with full qualified path
So far it works without problems. The sTargetFile exists (reviewed by debugging).
-------------------------------------------
3) Now i want to open the renamed file for reading
CFile file;
file.Open(sTargetFile, CFile::modeRead);
-------------------------------------------
After that on some machines (with Windows 7) i get an CFileException::sharingViolation exception.
But on the most machines it works without an exception.
What is the matter for this exception?
Does the CFile::Rename still block the file?
How i can wait until the file is definitively closed?
Please help me!
modified on Sunday, January 31, 2010 5:51 AM
|
|
|
|
|
|
good idea, but the problem is a time-critical affair. This means as soon as i have for example a built-in debug message after CFile:Rename and CFile:Open, the problem disappears. So i can not look which process has the file between CFile:Rename and CFile:Open.
Any other help there?
|
|
|
|
|
Quick question - I'm wondering how I can detect when the user presses the enter key on the edit control in my dialogBox(), ie what messages do i need to handle in the dialog procedure?
|
|
|
|
|
WM_COMMAND with LOWORD(wParam) == IDOK and (HWND)lParam == your edit control HWND.
cheers,
AR
|
|
|
|
|
thanks for that! Works beautifully 
|
|
|
|
|
You're welcome 
|
|
|
|
|
You may also want to investigate whether the ES_WANTRETURN setting is appropriate to your control.
MVP 2010 - are they mad?
|
|
|
|
|