|
Hi,
for the header... I'm not sure, but for normal places... you can check which item (row) is, and compare the subitems (columns).
In any case I recommend you to take a look in the CListCtrl articles that are in the site. They would explain you a lot and maybe give you some idea or direct solution.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi all. I'm working on a project to a subject in university and i'm going through a hard time trying in everyway i know and looking out in the net for solutions but i cant figure it out.
So the objective is to mix Visual Basic with a DLL made from C++. with simple functions it works, but now im calling from VB a function in the DLL sending one number and the function should go to the .txt and find the number of the line that number is. as it wasnt working i tryied in a simple c++ project with a main to do a "manual debugging" with returns and printfs. lol so here is the code. (don't mind the includes here, they're just there because they came with the copy-past from the DLL.) btw the most part of this code was copied from the internet and "moulded" to my problem.
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<fstream>
#include <string>
int escolha_cod(double saldo,int escolha)
{
FILE *codigo;
int i=0,linha=0,j=0,aux=0;
char vec[2];
using namespace std;
string line;
ifstream myfile ("codigo.txt");
if (myfile.is_open())
{
for(i=0;i<10;i++)
{
getline(myfile,line);
const char *c_line;
strncpy(vec,line.c_str(),3);
aux=atoi(&vec[0]);
if(aux==escolha)
{linha=i;
i=10;}
}
myfile.close();
}return 47;
}
int main()
{int var;
var=escolha_cod(10,12);
printf("%d",var);
getchar();
return 0;}
If i put the "return 47;" right after "if (myfile.is_open()){" the printf says: 4403792
any idea? i would really appreciate a quick answer =) thks in advance guys!
|
|
|
|
|
Review your post; we can't see any of the "<" or ">" charcters or what's between them! The variable codigo seems unused.
Steve
|
|
|
|
|
why do i need an "<"or">" in my code?? i believe i didnt understand what you're trying to say..
yes codigo shouldn't be there lol its trash from others experiments lol
|
|
|
|
|
Have a look at your post. What does #include do without any file name after it?!?!?
Steve
|
|
|
|
|
right.. so i added this:
#include codigo.txt (with the rectangular brackets)
but it gives me this error: "dll.cpp:8:22: codigo.txt: No such file or directory"
i put the file in the possible directories (im using MinGW) I:\Programas\MinGWStudio\Templates\dll\Debug and I:\Programas\MinGWStudio\Templates\dll (because i dont know where its suppose to be..
-- modified at 3:20 Monday 4th June, 2007
|
|
|
|
|
GatoFedorento47 wrote: right.. so i added this:
#include codigo.txt
He meant to modify your post so that the angle brackets did not get "eaten." Modifying your code is obviously going to cause problems.
Notice the two angle brackets that are above the smileys.
"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
|
|
|
|
|
#include<windows.h>
#include<<stdio.h>
#include<<stdlib.h>
#include<<stdio.h>
#include<<time.h>
#include<<fstream>
#include<string>
#include <codigo.txt>
int="" escolha_cod(double="" saldo,int="" escolha)
{
="" file="" *codigo;
int="" i="0,linha=0,j=0,aux=0;
char" vec[2];
using="" namespace="" std;
string="" line;
="" ifstream="" myfile="" ("codigo.txt");
if="" (myfile.is_open())
{return="" 47;
="" for(i="0;i<10;i++)
" {=""
="" getline(myfile,line);
=""
="" const="" char="" *c_line;
="" strncpy(vec,line.c_str(),3);
="" aux="atoi(&vec[0]);
" if(aux="=escolha)
" {linha="i;
" }
myfile.close();
}
return="" 47;
}
int="" main()
{int="" var;
var="escolha_cod(10,12);
printf("%d",var);
getchar();
return" 0;}
apparently="" the="" problem="" is="" with="" <code="">if (myfile.is_open()), so i just wanted to know how do you open files.. :s
|
|
|
|
|
Is this supposed to be an improvement? Paste your code into a reply, highlight the code, and click the "pre" formatting button (above the smileys). Now for the important part: click the Preview button. If anything is askew, fix it. If any angle brackets are missing, delete the left angle bracket and then click the '<' above the smileys.
"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
|
|
|
|
|
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<fstream>
#include<string>
#include<codigo.txt>
int escolha_cod(double saldo,int escolha)
{
int i=0,linha=0,j=0,aux=0;
char vec[2];
using namespace std;
string line;
ifstream myfile ("codigo.txt");
if (myfile.is_open())
{
for(i=0;i<10;i++)
{
getline(myfile,line);
const char *c_line;
strncpy(vec,line.c_str(),3);
aux=atoi(&vec[0]);
if(aux==escolha)
{linha=i;
i=10;}
}
myfile.close();
}return 47;
}
int main()
{int var;
var=escolha_cod(10,12);
printf("%d",var);
getchar();
return 0;}
sorry! its the first time im writing here.. i think now is just the way u asked..
|
|
|
|
|
GatoFedorento47 wrote: sorry! its the first time im writing here..
No problem. Everyone's got to start somewhere.
GatoFedorento47 wrote: i think now is just the way u asked..
Yep. All you got to do now is fix the problem.
"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
|
|
|
|
|
that's why im posting here.. so anyone can give me ideias on how to put this right.
|
|
|
|
|
GatoFedorento47 wrote: so anyone can give me ideias on how to put this right.
I already gave you the solution here.
"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
|
|
|
|
|
GatoFedorento47 wrote: strncpy(vec,line.c_str(),3);
This is guaranteed to fail. The variable vec can only hold only character plus the '\0' terminator.
GatoFedorento47 wrote: aux=atoi(&vec[0]);
Is the same as:
aux = atoi(vec); escolha_cod() returns nothing but 47. Is this intentional?
GatoFedorento47 wrote: ifstream myfile ("codigo.txt");
Shouldn't you be specifiying a path with this?
"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
|
|
|
|
|
for the two first problems, i still have to search in the net, but about escolha_cod() returning 47 was intentionla because in the function i've been moving it around to see where the function was failing. and it's after:
if (myfile.is_open()){
So most probably this is the error, but i dont understand, everybody uses it! and its not working 4 me
|
|
|
|
|
GatoFedorento47 wrote: ...but i dont understand...
The likely cause is the aforementioned call to strncpy() , which is stepping over part of the return value on the stack.
GatoFedorento47 wrote: ...everybody uses it!
But not in it's current form.
"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
|
|
|
|
|
DavidCrow wrote: The likely cause is the aforementioned call to strncpy(), which is stepping over part of the return value on the stack.
allright.. im not english as U might guessed by now, so i dont really understand "aforementioned". searched in the net and its "the previous" ? but strncpy( ) is called after if (myfile.is_open()) . i believe the function cant get access to the file in question because if i put the return after this piece of code it gives me something completely different from 47 :s anyway, if the error is indeed what u'r saying could you explain it for "dummies" pls
|
|
|
|
|
GatoFedorento47 wrote: i believe the function cant get access to the file in question because if i put the return after this piece of code it gives me something completely different from 47
So what you are saying is that you have this:
int escolha_cod(double saldo,int escolha)
{
FILE *codigo;
int i=0,linha=0,j=0,aux=0;
char vec[2];
using namespace std;
string line;
ifstream myfile ("codigo.txt");
if (myfile.is_open())
return 47;
{
for(i=0;i<10;i++)
{
getline(myfile,line);
const char *c_line;
strncpy(vec,line.c_str(),3);
aux=atoi(&vec[0]);
if(aux==escolha)
{
linha=i;
i=10;
}
}
myfile.close();
}
return 47;
} Is that right?
"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
|
|
|
|
|
if (myfile.is_open())<br />
{return 47;
... like this lol
|
|
|
|
|
GatoFedorento47 wrote: myfile.is_open())
Ok, so is the myfile.is_open() statement evaluating to zero or a non-zero value? In other words, which of the two return statements is being executed?
"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
|
|
|
|
|
ok.. i dont know what i did, but now is working! lol .. now that that is working i copied to visual studio (where im building my dll) and compiled. everythings fine, but when i run my actual program made in VB when i call the function it keeps returning 0 again arghhh i hate this stupid things..
|
|
|
|
|
GatoFedorento47 wrote: ...but now is working!
Not if you haven't increased the size of the vec variable.
GatoFedorento47 wrote: ...but when i run my actual program made in VB when i call the function it keeps returning 0 again
I suspect it is a relative .vs absolute path issue.
"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
|
|
|
|
|
DavidCrow wrote: I suspect it is a relative .vs absolute path issue.
sorry.. didn.t understand, what do you mean? that VB doesn't know where is the file?
|
|
|
|
|
GatoFedorento47 wrote: didn.t understand, what do you mean?
See here.
GatoFedorento47 wrote: that VB doesn't know where is the file?
Exactly. Set a breakpoint in your DLL on the is_open() statement to verify.
"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
|
|
|
|
|
yes, the problem was that the file wasn't in the place it should be. lol. what i did was: instead of reading, i put write and by default, if the file doesn't exist, it creates one. after running the program, i just searched through windows search and found that test file. that way i knew where to put my original txts thks for all the help [[]]
|
|
|
|