mitrmkar 1,056 Posting Virtuoso

I need to pass a non-static data member in one class (class Disks, data member disks) to another class (ToH) to its static bool function, so I can test that value.

In that case, modify the ToH::test() to take as an argument a variable of type Disks , i.e.

bool ToH::test(Disks & obj)
// or maybe ...
// bool ToH::test([B]const [/B]Disks & obj)
{
    bool answer;

    // if disks is a private/protected member, you might change it to public
    // or make ToH friend of Disks or add a method e.g. GetDisks().
    if(obj.disks == 1)
    ...
}
// and used like
int main()
{
    Disks obj(3);
    bool b = ToH::test(obj);
    ...
}

or pass just the value of disks, so it would be

bool ToH::test(const int disks)
{
    bool answer;

    if(disks == 1)
    ...
}
// and used like
int main()
{
    Disks obj(3);
    bool b = ToH::test(obj.disks);
    ...
}
mitrmkar 1,056 Posting Virtuoso

To get the first listbox entry (assuming Listbox is a member variable)

CString str;
Listbox.GetText(0, str);

You can get the number of items in the listbox using Listbox.GetCount().

mitrmkar 1,056 Posting Virtuoso

You need to be more specific about the listboxes. Are they MFC's CListBoxes or generic Windows LISTBOXes or some other type of listboxes??

mitrmkar 1,056 Posting Virtuoso

i dont understand watz rong w dis.........

Please, take some time and read the section Keep It Clean

mitrmkar 1,056 Posting Virtuoso

You need to open the file in binary mode in order to prevent CR/LF translation.

char * fbuffer;
long fsize;
ifstream cpy ("sample.txt", [B]ios::binary[/B]);
...

Writing a '\0' at the end of file does not fix the problem.

mitrmkar 1,056 Posting Virtuoso

SetPriorityClass takes the handle of the process, not the thread's handle. So you need to have

HANDLE hProcess = GetCurrentProcess();

Is there a utility to view threads and how they tick on and off of the processor?

You might use
Process Explorer

mitrmkar 1,056 Posting Virtuoso

ofstream nnewfile (textBox2->Text &".txt");

If you use VC 2008, you can convert textBox2->Text to std::string using
marshal_as

or with earlier versions, e.g.
http://msdn.microsoft.com/en-us/library/1b4az623.aspx

mitrmkar 1,056 Posting Virtuoso

HELP HELP HELP.. LOL I'M NOT GETTING IT.. I WONDER IF IT HAS TO DO WITH THE NAME OF THE FILE OR SOMETHING??

Here is a commented and formatted version ...

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{     
    ifstream inFile;
    ofstream outFile;

    // Specify the[B] full path to the input file[/B],
    // in this case in the root of the C: drive.
    // If you specify the file name only, then the
    // file has to be in the program's current working
    // directory in order to be opened.
    inFile.open("c:\\readGrosspayMinustax.cpp");

    if (inFile.fail())
    {
        cerr << "error opening input file.\n\n";
        system("pause");
        exit(1);
    }
    
    outFile.open("outputGrosspay");

    if (outFile.fail())
    {
        cerr << "error opening input file.\n\n";
        system("pause");
        exit(1);
    }

    outFile.setf(ios::fixed);

    // [B]initialize all used variables[/B] ...
    int employee = 1;
    int exemptions = 0, 
        taxbracket = 0;

    double  hours = 0, 
            overtime = 0, 
            payrate = 0, 
            grosspay = 0, 
            netpay = 0, 
            rate = 0, 
            tax = 0;

    // read in the 4 numbers and assign to the variables
    while (inFile >> hours >> payrate >> taxbracket >> exemptions)
    {
        if (hours > 40)
        {
            overtime = hours - 40;
            hours = 40;
        }   
        else
        {
            overtime = 0;
            grosspay = hours * payrate + overtime * payrate * 1.5;
        }      
        
        if (taxbracket == 1)
            rate = .13;
        else if (taxbracket == 2)
            rate = .27;
        else
            rate = .35;

        tax = grosspay * (rate - .01 * exemptions);
        netpay = grosspay - tax;

        cout    << fixed …
mitrmkar 1,056 Posting Virtuoso

And if I have a reference then I need to initialize it.

Following is an usage example of using a function taking the argument by reference

// takes a Disks object by reference
void some_function(Disks & aDisk)
{
    if(aDisk.disks == 1)
    {
        // do something here
    }
}

int main()
{
    Disks obj(123);

    // invoke some_function on obj
    some_function(obj);

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

Did I do the code tags correctly this last time??
mikelle

Yes you did.
Only the formatting of code was lacking, e.g. proper indentation as below, works wonders ...

if (hours > 40)
{
    overtime = hours - 40;
    hours = 40;
}
else
{  // <- clearly state where the else block starts
    overtime = 0;
} // <- and where it ends
mitrmkar 1,056 Posting Virtuoso

The reading part still continued ...

// Following reads 5 numbers ...
while (inFile >> hours >> employee >> payrate >> taxbracket >> exemptions)

But the input lines contain only 4 numbers, so you need to drop the excess variable from the above code line. I guess the variable is employee , which appears to be a counter (note that you don't increment this counter anywhere).

Then you probably want to move those cout statements to be inside the while() loop.

Last but not least, in addition to the code tags, proper formatting makes the code for anyone much easier to read (and you'll probably get more replies).

mitrmkar 1,056 Posting Virtuoso

if(Disks::disks == 1) will work only if the disks is a static variable, i.e.

class Disks
{
   ...
   static int disks;
   ...
};

If it's not feasible to have it as static, then you need an Disks object, i.e.

void some_function(Disks & aDisk)
{
    if(aDisk.disks == 1)
    ...
mitrmkar 1,056 Posting Virtuoso

I'm repeating VernonDozier here ...

Code tags and formatting please:

Just so that you get the file reading working, the following is almost completely wrong
(the use of placing the read operation inside the while() is good)

while (hours, employee, payrate, taxbracket, exemptions >> inFile)

Assuming you have five numbers on one line, you'll read those ...

while (inFile >> hours >> employee >> payrate >> taxbracket >> exemptions)
mitrmkar 1,056 Posting Virtuoso

Here is some general information on background applications (a.k.a. services or daemons) ...
http://en.wikipedia.org/wiki/Daemon_%28computer_software%29

mitrmkar 1,056 Posting Virtuoso

You are not allocating enough storage, change from

prior = (double*) malloc(nzcwint);

to

prior = (double*) malloc(nzcwint * sizeof(double));

// + allocation of cwint in same fashion ...

Then again, why aren't you using new/delete, i.e.

prior = new double[nzcwint];
// etc
// and eventually ...
delete [] prior;

Then about conversions, stringstream is capable of doing the conversions you need. Consider ...

string test = "12301230 786345.94";
    long i;
    double d;
    stringstream sstrm;

    sstrm << test;

    if(sstrm >> i >> d)
    {
        cout << "i: " << i << "\nd: " << fixed << d;
    }
    else
    {
        cout << "Conversion error";
    }
mitrmkar 1,056 Posting Virtuoso

and when add this statment
(word.substr(word.find(' '))
,appear problem in the run (abnormal program termnation)

Here is one way to trim leading whitespace

string test_string = "    test_string";
    string ws = " \t";

    // lookup the position of the first non-whitespace char, if any
    std::string::size_type pos = test_string.find_first_not_of(ws);

    if(std::string::npos == pos)
    {
        // string contains only whitespace
    }
    else
    {
        // drop the leading whitespace
        test_string.erase(0, pos);
    }

    cout << "[" << test_string << "]" << endl;
Nick Evan commented: nice & clean example +6
mitrmkar 1,056 Posting Virtuoso

i read the file line by line
then store the lines in strings
but the space that is in the begin of line i want remove it before read the line and store it in the strings

Does the following make things clearer ?

std::string line;

// read a whole line ...
while(getline(infile, line))
{
    // the variable [B]line[/B] contains the whole line at this point

    // insert code here to trim the leading whitespace
    
    // insert code here to save the trimmed line
}
mitrmkar 1,056 Posting Virtuoso

You can use the init_priority attribute to have the initialization take place in correct order, see
http://gcc.gnu.org/onlinedocs/gcc-3.3.2/gcc/C---Attributes.html#C++%20Attributes.

And maybe you find the following useful too
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

mitrmkar 1,056 Posting Virtuoso

hi
i have an application made of several dialogs
each has its own exit button
my question:
whan i press the exit button ... iwant to exit the whole application (not exit the present dialog and return to the Previous one )
how can i do that .....please help me out with this
thank u all

Are you on Windows or ..? Are you using some GUI library?

mitrmkar 1,056 Posting Virtuoso

ParamValue must point to a large enough buffer to receive the information. The documentation should provide information wrt 'large enough buffer'.

You might use something like

const int GETMOVING_SIZE 1024;
char paramValue[GETMOVING_SIZE] = {0};

if(LT360LIB_CmdValue(handle, lt_GetMoving, paramValue))
{
    // here you can check the content of paramValue
}
mitrmkar 1,056 Posting Virtuoso

Good, such nitpicky compilers they make ;)

mitrmkar 1,056 Posting Virtuoso

hey mitrmkar just a quick question ( sorry forgot to mention it before)
i get this warning when i add the header file of the lt360
( i removed the solved tag so the thread can be spotted and checked)

:\program files\microsoft visual studio\vc98\include\lt360lib.h(185) : warning C4518: 'LONGINT ' : storage-class or type specifier(s) unexpected here; ignored
e:\program files\microsoft visual studio\vc98\include\lt360lib.h(185) : warning C4230: anachronism used : modifiers/qualifiers interspersed, qualifier ignored

project.obj - 0 error(s), 2 warning(s)

as you can see no errors but warnings only ,but when i recompile the warnings go away and until now i had no problems.Is it ok to continue or are there some changes that must be done?

thanks

I assume you have a misplaced __stdcall somewhere in the header file, e.g.

extern "C" __stdcall LONGINT LT360LIB_OpenLinkUSB(void);

which has to be

extern "C" LONGINT __stdcall LT360LIB_OpenLinkUSB(void);
mitrmkar 1,056 Posting Virtuoso

I want the program to shut down on line 27 and lines 28-33 I am trying to make something so if anyone types a command that is not programmed it will display an error message

wrt lines 28-33, you need then change to

if (choice == 5)
        ;
    else
    [B]{[/B]
        system("cls");
        cout << "\n Error: Invalid Command";
        Sleep(2000);
        system("cls");
        AmasiVillage();
     [B]}[/B]

Note that you are still calling AmasiVillage() recursively, in case of invalid command.

mitrmkar 1,056 Posting Virtuoso

Looking at the main() ...

int main() 
{ 
   employee *emp;

   emp = new employee; // this is missing ...

   emp->getData();
...
mitrmkar 1,056 Posting Virtuoso

How about changing from

char fname[20], lname[20];

to

string fname; string lname;
mitrmkar 1,056 Posting Virtuoso

it is not exactly that. I have got:

void main()
{
    bwlabel(image,8);
}

bwlabel.h

void order(void);
void bubble(void);
void bwlabel (System::Drawing::Bitmap^ image, int number);

bwlabel.cpp

void order(void)
{
   //instructions
}
void bubble(void)
{
     //instructions
}

void bwlabel (System::Drawing::Bitmap^ image, int number)
{
    order()
    bubble()

}

I think that it is not the same scenario but maybe I am wrong!

That should be OK, depends of course on what order() and bubble() actually are doing.

PS. void main() should really be int main() see e.g.
http://www.research.att.com/%7Ebs/bs_faq2.html#void-main

mitrmkar 1,056 Posting Virtuoso

Maybe you have a following kind of scenario ...

void fun1();

void fun2()
{
    fun1();
}

void fun1()
{
    fun2();
}

int main()
{
    fun1();
    return 0;
}
mitrmkar 1,056 Posting Virtuoso

so plz tell me what is the solution for it??

Pick up the habbit of using e.g. the following compiler options -W -pedantic -Wall.
When you compile, work through the error/warning list until your program compiles cleanly.

Here is a guide
http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Warning-Options.html#Warning-Options

iamthwee commented: YES - although that isn't how you spell habbit. +15
mitrmkar 1,056 Posting Virtuoso

Code is compiling.

Which compiler are you using? E.g. char buff[str.size()]; should cause an error.

mitrmkar 1,056 Posting Virtuoso
system("\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"");

Try this one ..

system("\"\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"\"");
mitrmkar 1,056 Posting Virtuoso

You increment i too early ...

emp1[i]->setProperties(emp_id,fname,lname,hours_worked,hourly_rate,employee_type_flag,given_gross_pay);

i++; // <- incremented too early
employee::headers();
// emp1[i] is not pointing to an allocated item at this point
emp1[i]->calc_gross_pay();

Note that you are not handling the case where employee_type_flag is something else than 's' or 'h'. There may be other errors too, I didn't look too closely, but fixing the getData() gets you started.

mitrmkar 1,056 Posting Virtuoso

You increment i too early ...

emp1[i]->setProperties(emp_id,fname,lname,hours_worked,hourly_rate,employee_type_flag,given_gross_pay);

i++; // <- incremented too early
employee::headers();
// emp1[i] is not pointing to an allocated item at this point
emp1[i]->calc_gross_pay();

Note that you are not handling the case where employee_type_flag is something else than 's' or 'h'.

mitrmkar 1,056 Posting Virtuoso
LT360LIB_Cmdvalue(handle,lt_goto_ccw,'nnn.n')

That's how a string is specified in Pascal. In C/C++ you have to stick with double quotes when you specify strings. Happy coding ...

mitrmkar 1,056 Posting Virtuoso

by the way one more thring if i create a .def file for a .dll and from the def file i found out that a certain function takes 3bytes e.g@3, is it ok to edit the .def file to make it take 4 (as we did) e.g changing the @3 to @4 or shouldn't i change the header file to suite the .dll needs

It appears that you are confused by the link ordinals in the .def files. If you take a look at the original .def file, there may be e.g a line like

LT360LIB_OpenLinkUSB         @2   ; LT360LIB_OpenLinkUSB

The '@2' is the ordinal which also can be used for linking, i.e. linking completely without the symbolic function name. So, don't modify/remove those ordinals, just append the function naming decoration to the function names, e.g.

LT360LIB_OpenLinkUSB[B]@0[/B]         @2   ; LT360LIB_OpenLinkUSB

and so on.


Now, as a check-list, using LT360LIB_OpenLinkUSB() as an example, things should look like:

In the header file:

extern "C" __stdcall LONGINT LT360LIB_OpenLinkUSB(void);

In the .def file

LT360LIB_OpenLinkUSB@0          @[I]<link ordinal>[/I]

In the generated .lib file: (use dumpbin /EXPORTS)

[I]<link ordinal>[/I]            _LT360LIB_OpenLinkUSB@0

And in the code

LONGINT val = LT360LIB_OpenLinkUSB();
mike issa commented: exactly the answer needed +2
mitrmkar 1,056 Posting Virtuoso

There must be no space between the function name and the '@', if there is, the meaning of the '@' + the following number changes to mean a 'link ordinal'.

So, use it as below ...

LIBRARY     LT360LIB.DLL

EXPORTS
    LT360LIB_CloseLink@4   
    LT360LIB_Cmd@8   
    LT360LIB_CmdIndexValue@10   
    LT360LIB_CmdString@4  
    LT360LIB_CmdValue@9   
    LT360LIB_GetDllVerDate@2   
    LT360LIB_GetUsbFirmwareVerDate@6   
    LT360LIB_LinkedCnt@0   
    LT360LIB_OpenLinkCOM@8   
    LT360LIB_OpenLinkUSB@0   
    LT360LIB_ReadBinary@17  
    LT360LIB_WriteBinary@17

just to make sure if the function takes no arguments @0

Yes.

and when i use

typedef unsigned char * Pointer;

pointer is equal to one byte right

No, it is 4, not 1 (you are dealing with a pointer).

i hope all the @value are correct

If in doubt about the sizes, you can check by e.g.

printf("%u\n",sizeof(unsigned char *));
mitrmkar 1,056 Posting Virtuoso

The .def file you are using is wrong.
Given the prototype extern "C" LONGBOOL __stdcall LT360LIB_CloseLink(LONGINT Handle); The counterpart entry in the .def file must be

LT360LIB_CloseLink@4

i.e. function name, followed by '@', followed by the number of the bytes (in decimal) the function's arguments use.

After you've gone through and fixed all the function's in the .def file, then use LIB.exe to generate a new .LIB.

mitrmkar 1,056 Posting Virtuoso

Post the output of the following command:

dumpbin /EXPORTS LT360LIB.lib


I guess the Pointer type is:

typedef unsigned char * Pointer;

and the LONGBOOL type is

typedef  int LONGBOOL;

Stressing again, try verifying these typedefs with the software vendor, so you don't have to be making guesses.

I think the header is otherwise OK.

mitrmkar 1,056 Posting Virtuoso

by the way when i created th lib file i got a .exp file what is it for?

.exp files contain information about exported items, used when your program both imports/exports from another one.

mitrmkar 1,056 Posting Virtuoso

Adding to what niek_e already mentioned, something like the following might be close to what you are after ...

for(double i = 0; i < 1.05; i += 0.05)
{
	this->Opacity = i;
	this->Refresh();
}

I am trying to "Fade In" a Form when this form is opened

Shouldn't it then be in the Form's Load event rather than in the Activated event?

mitrmkar 1,056 Posting Virtuoso

now the project its compiling and building i got errors when i used the __stdcall but when i removed it it worked

Sounds as there's still some sort of mismatch if it seems to work without __stdcall prototypes. If you get run-time errors (in debug builds) complaining about a failure to save ESP properly, then you'll have to revise and fix this import library generation. With release builds, you'll probably get access violation errors.

About the LONGBOOL, I guess that it might be actually


typedef int LONGBOOL;


Anyway, try to check those typedefs with the software vendor. (Who really should provide a ready-to-use package).

mitrmkar 1,056 Posting Virtuoso

I used a program called implib32 i created a.lib file directly from the dll and i linked it with my project but i got this error message
"
lt360.obj : error LNK2001: unresolved external symbol _LT360LIB_OpenLinkUSB
Debug/lt360.exe : fatal error LNK1120: 1 unresolved externals
"

At compile time, the LT360LIB_OpenLinkUSB() is apparently seen as __cdecl but it is __stdcall.
So you probably have been missing the step(s) to modify the header so that every function prototype is: extern "C" <return type> __stdcall function(<args>);

mitrmkar 1,056 Posting Virtuoso

You might use std::string find() to see if the line contains the search string.
And when it does, you can extract the rest of the line using std::string substr().

find()
substr()

mitrmkar 1,056 Posting Virtuoso

was created using borland are there any changes that must be done on it before using it in VC++

Just occurred to me that probably you'll have to do some changes before using LIB.exe. Apparently the .DLL functions use __stdcall calling convention, so you'll have to modify each function so that they'll conform to the MS's name decoration convention. In practice, every function is to be appended an '@', followed by the number of bytes taken by the arguments.

I.e. if you have a library function void __stdcall function(char *, char *, char *); it would be function@12 in the .def file.

Furthermore, in your project which will include the generated .lib + its accompanying header,
1) use extern "C" {} in the header file to wrap all the exported functions.
2) make sure that the exported functions are seen as __stdcall , either use the /Gz switch or explicitly add the __stdcall to each function prototype.

Note that LIB.exe will additionally prefix every function with an underscore. So if you'll look into the .LIB's exports by e.g. dumpbin.exe /EXPORTS LT360LIB.lib you'll see something like _LT360LIB_CloseLink@0 (assuming LT360LIB_CloseLink does not arguments)

If you end up having mixed-up calling conventions, your program will crash at run-time.

mitrmkar 1,056 Posting Virtuoso
Day:
                                printf("\n1:Mon\t2:Tue\t3:Wed\t4:Thu\n5:Fri\t6:Sat\t7:Sun\nEnter value-> ");
                                scanf("%d",&x);
                                char dd1[5]="MON"; char dd2[5]="TUE"; char dd3[5]="WED";
                                char dd4[5]="THU"; char dd5[5]="FRI"; char dd6[5]="SAT";
                                char dd7[5]="SUN";
                                if(x==1){  strcpy(dd,dd1);   } 
                                if(x==2){  strcpy(dd,dd2);   }    
                                if(x==3){  strcpy(dd,dd3);   } 
                                if(x==4){  strcpy(dd,dd4);   } 
                                if(x==5){  strcpy(dd,dd5);   } 
                                if(x==6){  strcpy(dd,dd6);   }
                                if(x==7){  strcpy(dd,dd7);   } //printf("%s",dd);
                                if(x>7 || x<1)
                                {
                                       cout<<"\nPlease Enter Valid Option\n";
                                       goto Day ;
                                }

this is part of my code.....
If i given input any character it goes infinite loop...
E.g:- q
if gives int value it works fine
how to resolve it??

You need to check the return value of scanf() which tells you whether it succeeded or not (in getting an int from the user).

scanf()

mitrmkar 1,056 Posting Virtuoso

For example ... printf("%03d", 12); prints:

012


printf()

mitrmkar 1,056 Posting Virtuoso

hi all
i was a able to create a .def file from lt360lib.dll using Borland C++ (impdef.exe)

LIBRARY     LT360LIB.DLL

EXPORTS
    LT360LIB_CloseLink             @3   
    LT360LIB_Cmd                   @7   
    LT360LIB_CmdIndexValue         @9   
    LT360LIB_CmdString             @10  
    LT360LIB_CmdValue              @8   
    LT360LIB_GetDllVerDate         @1   
    LT360LIB_GetUsbFirmwareVerDate @6   
    LT360LIB_LinkedCnt             @2   
    LT360LIB_OpenLinkCOM           @5   
    LT360LIB_OpenLinkUSB           @4   
    LT360LIB_ReadBinary            @12  
    LT360LIB_WriteBinary           @11

how can i convert this .def into a .lib file.
I use Microsoft visual studio 6.0, and since it was created using borland are there any changes that must be done on it before using it in VC++

Assuming .def file name is LT360LIB.def, try MS's LIB utility as follows:

LIB /DEF:LT360LIB.def

mitrmkar 1,056 Posting Virtuoso

Hi!
#include <stdio.h>
main()
{
int p, n;
float r, si;
printf("Enter values of p, n, and r");
scanf("%d, %d, %f", &d, &d, &f);
si=p*n*r/100;
printf("Simple interest=%f", si);
getchar();
return 0;
}
There is no error in this program. Output is also right but only for small integers.

I think you posted wrong version of your code, namely it should not even compile due to the line scanf("%d, %d, %f", &d, &d, &f); You don't have the variables d , or f in the program. Maybe you'll post the working code you are having problems with.

mitrmkar 1,056 Posting Virtuoso

Thanks for the reply my friend
when i try to use

"e:\>bcf\bin\impdef lt360lib.dll > lt360lib.def"

i get this

"Syntax: IMPDEF [options] destname[.def] srcname[.dll]
Options:
-h Emit hints
"
and another question where should the output be located, is it in the same directory where the impdef.exe is located ?
i.e
"e:\>bcf\bin\lt360lib.def"
thanks again

I think dougy83 referred to another (somewhat simplified) impdef utility which you can find here
http://mirrors.zoreil.com/webclub.kcom.ne.jp/ma/colinp/gcc.html

So you might give that one a try, using the command:

impdef lt360lib.dll > lt360lib.def

mitrmkar 1,056 Posting Virtuoso

This seems to be a feature in VS. If you look into the Form's InitializeComponent() code, you'll see that the Designer has added the second panel as a control of the first one, i.e. something like: this->panel43->Controls->Add(this->panel41); This arrangement seems to occur acutomatically whenever the two panels overlap in the Form Designer. So maybe you have to devise something else instead of overlapping panels.

mitrmkar 1,056 Posting Virtuoso

I still havent figured this one out

Have you tried the printer vendor's support facilities?