|
Take a look on my Infrared Communication with your Mobile Phone article.
The sample application uses the IrDA port like a serial port on the Desktop PC, so you can simple use the source code in your Desktop application.
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I want to display current date in CDateTimeCtrl in VC++ and
fomat should be in MMDDYY. I was unable to get format functions in the intelesence
Any suggesstions pl
With Thanks & Regards
--Kamesh
|
|
|
|
|
Hi,
I have a dll witch staticlty linked with the kernel32.dll and I need to replace all the calles of the CreateFile function to another DLL (like hook) but I'm tring to do it by changing the binary PE of the dll.
I'm using MS Detour, but I did not find a compleate documentation.
Any one could help me?
|
|
|
|
|
It sound not good to link staticly. Maybe there is some design error.
(Do you like debugging???;P)
It´s better to link dynamicly or call the API. There is better portability and that seems to be your problem.
Try this @ home. (B&B)
|
|
|
|
|
Suppose I have to read an arbitrary number of recoreds from a file into an array. each record contains student name, age, school...
For now each record should be saved as a string. So I have an array of string, but I don't know of what size.
What is the "standard approach" to this in c++?
In Java I use Vector class, in c I use malloc and realloc... What would you do in c++ (I'm new to c++ )
Thanks.
-----------------------
But what did I do ?
|
|
|
|
|
Use STL, Standard Template Library. There you will find things like string, vector, list, map etc. to help you out.
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
I don't know if ther's a "standard approach" but what I'll do is first to read the string in a large buffer (large enough to store the largest string in your file) and then allocate dynamically memory for the string.
You can do it like this:
<br />
char Buffer[255];
<br />
fscanf(YourFile,"%s",Buffer);
<br />
char* YourString = new char[strlen(Buffer)];
strcpy(YourString,Buffer);<br />
Take a look at the fscanf documentation for all the format specifications and how to use it!
|
|
|
|
|
Thank You Fredrik and Cedric for your quick replies.
1. I cannot use STL yet. Haven't learned it so if a vector or linked list will be the solution, I will have to implement them by my own (trying to avoid that )
2. Maybe I didn't explain well my intentions - I receive a large file of un known size. In each line I have a string that should be stored in an array of strings. So I read line by line (untill EOF) and assign the i'th row in array_of_strings[i]. I don't know how many lines the file contains so I don't know how much space to allocate. (BTW, fscanf is c-like writing and I'd prefer c++. I use ifstream).
Thanks Again.
-----------------------
But what did I do?
|
|
|
|
|
STL is not that hard to use, but very nice to work with, so give it a try.
If you use std::vector you can pre-allocate space (if you want) and then the allocation increases automagically whenever needed, so you need not bother about allocation.
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
The crude way is to read the file once, to count the number of lines, possibly checking the max length of the lines, then create an array of strings, and re read the file.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Makover wrote:
I cannot use STL yet. Haven't learned it
Makover wrote:
I will have to implement them by my own
If you can make that, you sure can learn to use STL-containers in less time. The interfaces are similar to what you know already, and it is exactly what you want.
what you want semms quite simple:
Read the line into a std::string , parse that one into pieces and push_back() every piece into a std::vector < std::string > .
You then have a container that behaves quite like an array (operator[] and such).
Try it!
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
If you want to do it the MFC way you should use the CArray (index-related) or the CList (referenz-related). There are different types derived so read the MSDN carefully before coding.
I would use CStringArray.
Try this @ home. (B&B)
|
|
|
|
|
I was required to be as system independent as possible so I'm not "allowed" to use MFC.
I'll give a try to STL. Anyway I will learn later.
Thank You all (Fredrik , cedric , Ted & KarstenK) for your time and help (I love this forum )
-----------------------
But what did I do?
|
|
|
|
|
if your method works in c porting to c++ is less than simple ! change extension to c++ then check you type casts ! see errors and repair them !
but you shouldn`t see any !
I am the mighty keeper of the book on knowledge . Contact me to get your copy .
|
|
|
|
|
dear all
i want to use a global variable in my mfc dialog based app.
i defined a var in stdafx.h
the code compiles but gives a linker error :- multiple instances found.
so where do i defin my global vars which could be used throughout the classes.
also can these variables be static.
regards
|
|
|
|
|
Anywhere in a *.cpp file (source file) of your project write:
unsigned int g_uiMyGlobalUnsignedIntVar;
And to use the global variable everywhere in your project add the following in the stdafx.h file:
extern unsigned int g_uiMyGlobalUnsignedIntVar;
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
thanx 4 ur reply, but i have a doubt
there r three cpp files,
one is stdafx.cpp, App.cpp, Dlg.cpp
can i define the variable in any of these files.
SHOULD I DECLARE IT outside the classes?
thanx
|
|
|
|
|
Declare it as extern in your stdafx.h and define it in your source file (.cpp).
rishabhs wrote:
can i define the variable in any of these files.
No, just in one file!
ps. try what happens if you do!
rishabhs wrote:
SHOULD I DECLARE IT outside the classes?
YES!
If you declare it inside a class it's not a global varible!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
i understand the difference between declaration and definiation of functions.
but how these are different in case of variables.
|
|
|
|
|
rishabhs wrote:
can i define the variable in any of these files.
No. Just in one file (otherwise the linker shows an error, because you use more than one variables with the same name).
rishabhs wrote:
SHOULD I DECLARE IT outside the classes?
Yes. If you declare it inside the class it's not a global variable, it's in the namespace of the class!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
You can also declare a variable inside the Main App class (CMyApp i.e.) and then use member functions on that class in order to access that var.
In order to be able to access that class you will only have to be sure that:
1. You have the header file of the CMyClass included in the .cpp or .h file in which you want to access the application.
2. declare the class as "extern CMyApp MyApp;"
after all of this you'll be able to:
MyApp.WhateverYouHaveDefinedAsPublicInYourClass...
WhateverYouHaveDefinedAsPublicInYourClass can be a function or a variable depending on your needs, in case you want to access a var, I know that it is a little bit of overhead, but it can be interesting to use SET/Get functions in order to access it, because in this way the behaviour will be controlled by a function and if sometime you need to change it you'll have to do it only in the function in your main class.
Hope this helps...
|
|
|
|
|
this response is what you don't want to hear (I know)...
Do not use globals! They are a sign for a bad design or a quick hack. Instead put data into classes and access it from there. In some cases make a member variable static... so you share one variable between all instances of a class.
See here[^] for a brief C++ tutorial.
For example declare static variable in class:
class CMyClass {
static int s_nVariable;
int GetValue() const { return s_nVariable; }
void SetValue(int nNewValue) { s_nVariable = nNewValue; }
};
and define it in CMyClass source code (in one file only!):
int CMyClass::s_nVariable = 0;
Hope I was not offtopic, Moak
|
|
|
|
|
cute :
in stdafx.h write : extern var_type var_name;
in stdafx.cpp write : var_type var_name=0;
that`s all !
I am the mighty keeper of the book on knowledge . Contact me to get your copy .
|
|
|
|
|
dear all,
how can i detect a system restart using WM_QUERRYSESSION.
i'm able to differentiate between a Logoff and shutdown using the message, but no clue whatsoever of differentiating between a system shutdown and system restart.
plz. respond
regards
|
|
|
|
|
plz. don't make me feel that there is no solution to this problem
|
|
|
|