|
The array declaration is:
struct DTC{<br />
char *Code;<br />
char *Description;<br />
char *Defined;<br />
}DTCodes[0x100];<br />
<br />
The code is:
for(i = 0; i < 100; i++)<br />
{<br />
k = 0;<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, ",");<br />
if(k == 1)<br />
strcat(tcCode, tcInputData);<br />
}while(k != 0);<br />
strcat(tcCode, "\0");<br />
DTCodes[i].Code = tcCode;<br />
ZeroMemory(tcCode, 0x06);<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, ",");<br />
if(k == 1);<br />
strcat(tcDescription, tcInputData);<br />
}while(k != 0);<br />
strcat(tcDescription, "\0");<br />
DTCodes[i].Description = tcDescription;<br />
ZeroMemory(tcDescription, 0xff);<br />
tcDescription = "";<br />
do{<br />
ReadFile(hDiskFile, tcInputData, 1, &dwBytesRead, NULL);<br />
if(dwBytesRead == 0)<br />
break;<br />
k = strcmp(tcInputData, "\n");<br />
if(k == 1)<br />
strcat(tcDefined, tcInputData);<br />
}while(k != 0);<br />
strcat(tcDefined, "\0");<br />
DTCodes[i].Defined = tcDefined;<br />
ZeroMemory(tcDefined, 0xff);<br />
tcDefined = "";<br />
}<br />
What would you recommend instead of strcmp?
|
|
|
|
|
I can't see, in the above code, for instance, the declaration of tcInputData .
jonsey29847 wrote: What would you recommend instead of strcmp?
the direct character comparison, for instance (if tcInputData is declared as character array or character pointer):
...
if (tcInputData[0] == ',')
...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Duh? I should have thought a little more, eh?
I can see the data in tcInputData, and I can see data in DTCodes[i].Code etc, when I try to read the data in another function, I get zilch. I seem to have trouble with scoping sometimes, but the struct is declared in the same include file the functions are defined in. The variable declarations are:
TCHAR *tcFileName;<br />
TCHAR *tcCode;<br />
TCHAR *tcDescription;<br />
TCHAR *tcDefined;<br />
TCHAR *tcInputData;<br />
tcFileName = LocalAlloc(LPTR, 0x100);<br />
tcCode = LocalAlloc(LPTR, 0x06);<br />
tcDescription = LocalAlloc(LPTR, 0xff);<br />
tcDefined = LocalAlloc(LPTR, 0xff);<br />
tcInputData = LocalAlloc(LPTR, 0x10);<br />
The struct is declared as follows:
struct DTC{<br />
char *Code;<br />
char *Description;<br />
char *Defined;<br />
}DTCodes[0x10];<br />
|
|
|
|
|
I think you have to be more careful on memory handling, for instance in the following lines
jonsey29847 wrote: DTCodes[i].Description = tcDescription;
ZeroMemory(tcDescription, 0xff);
you first assign tcDescription to DTCodes[i].Description and then erase the content of the memory pointed by both tcDescription and DTCodes[i].Description thus loosing the information.
BTW struct has to be declared in the header file, but is better to define DTCodes[0x10]; in one source file (you can use extern struct DTC DTCodes[0x10]; in the header file to make it visible by all of the source files).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thank you very much, can you explain how DTCodes[i].Description gets cleared after the assignment is made? I thought that I once the assignment was made I no longer needed tcDescription.
I also really appreciate the header file clarification, I have much work to do to straighten my code out.
|
|
|
|
|
jonsey29847 wrote: can you explain how DTCodes[i].Description gets cleared after the assignment is made? I thought that I once the assignment was made I no longer needed tcDescription
Description is a char pointer by definition
struct DTC{
char *Code;
char *Description;
char *Defined;
}DTCodes[0x100];
The following line
DTCodes[i].Description = tcDescription;
Makes DTCodes[i].Description pointing to memory area 'owned' by tcDescription . When you clear that memory area with the line
ZeroMemory(tcDescription, 0xff);
DTCodes[i].Description happens to point to the zeroed memory.
You have to copy the memory area content if you to use it as temporary storage.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
DTCodes[i].Code = tcCode; -> for every i assigning same global pointer tcCode.
ZeroMemory(tcCode, 0x06); -> effectively no data is stored in DTCodes[i].Code.
similarly,
DTCodes[i].Description = tcDescription;
ZeroMemory(tcDescription, 0xff);
DTCodes[i].Defined = tcDefined;
ZeroMemory(tcDefined, 0xff);
And exception can occur on buffer overrun,
strcat(tcCode, tcInputData); // what happens if tcCode string length > 0x06}
while(k != 0);
strcat(tcCode, "\0");
And why need strmp,strcat for single char operation, simple array manipulation is enough isn't it
k = strcmp(tcInputData, ","); -> if (tcInputData[0] != ',')
if(k == 1)
strcat(tcCode, tcInputData); -> tcCode[len++] = tcInputData[0];
|
|
|
|
|
Thank for your reply, my thinking was that once assignment was made I no longer needed tcCode etc, see previous reply. The exception was being thrown in the debug environment because I fat fingered a handle later in the code. tcCode will always be 4 bytes in length, its coming from the ODBII ECU in an automobile, thus I could be conservative with its length.
I will change my code for the single char comparison, you example is much cleaner.
Thanks
|
|
|
|
|
jonsey29847 wrote: my thinking was that once assignment was made I no longer needed tcCode etc
DTCodes[i].Code = tcCode;
ZeroMemory(tcCode, 0x06);
u no longer needed tcCode, but i think u need DTCodes[i].Code, since both points to same address clearing tcCode, clears DTCodes[i].Code.
and also ur allocating tcCode once outside the for loop, hence for all i, DTCodes[i].Code points to same tcCode.
assigning doesnot copies a C-Style string.
the following change may be useful,
struct DTC{
char Code[0x06];
...
}DTCodes[0x10];
and copy the string to DTCodes[i].Code[len++] = tcInputData[0];
|
|
|
|
|
Thanks very much, I have changed my code and it work very nicely.
|
|
|
|
|
Thanks, I made the change and it works very well!
|
|
|
|
|
I have a CDialogBar which uses a dialog resource, and the resource has some push buttons and a list box. I recently decided that I wanted the dialog bar to also have a tool bar at the top of its window. I've tried adding a CToolBar object, as well as tried adding a CToolBarCtrl, but I'm not able to get the tool bar to display.
I tried the same technique with adding a CToolBar object to a CDialog, and that worked fine (as did CToolBarCtrl), but when I try the same code within a CDialogBar, nothing appears.
Any suggestions? I've searched but I haven't found anything on the subject. I've found tips on how to add a CToolBar to a CDialog, but not how to add a CToolBar (or a CToolBarCtrl) to a CDialogBar.
Thanks,
Jeff
|
|
|
|
|
i am new on c++
i need to create a function with 2d array argument.
i mean i can use the integer numbers in a 2d array in my function.
And i also need to know how i can copy the information from the textboxes to a 2d array in vc++.
i hope you will help me.
thanks
|
|
|
|
|
Adnan Merter wrote: need to create a function with 2d array argument.
i mean i can use the integer numbers in a 2d array in my function.
for instance
int f(int a[3][2])
{
int i,j;
for(i=0; i<3; i++)
for(j=0; j<2; j++)
printf("a[%d][%d]=%d\n", i, j, a[i][j]);
return 0;
}
Adnan Merter wrote: And i also need to know how i can copy the information from the textboxes to a 2d array in vc++.
What is your difficulty about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
i have an array like x[5][5]
and i need to use it as an argument in my function i know how i use 1d array. i can it by using pointers.
void display (int *p, int size)<br />
{<br />
int i;<br />
<br />
for (i = 0; i < size; ++i)<br />
printf("%-5d%-5d \n", p[i],&p[i]);<br />
}<br />
<br />
int main()<br />
{<br />
int a[5] = {3, 8, 7, 6, 10};<br />
<br />
display(a, 5);<br />
return 0;<br />
}
but i dont know how ican use 2d arrays
|
|
|
|
|
For instance:
void display (int *p, int size0, int size1)
{
int i, j;
for (i = 0; i < size0; i++)
for (j = 0; j< size1; j++, p++)
printf("%-5d \n", *p );
}
int main()
{
int a[2][5] = {{3, 8, 7, 6, 10}, {6, 16, 14, 12, 20}};
display((int *)a, 2, 5);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi all
i want to simulate the ctrl + alt + delete keys
I am facing problem with this code. I able to get the reference of the "winlogon" desktop but am unable to simulate the ctrl + alt + delete keys.
can any one help please.
HDESK desktop;
ofstream myfile;
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
myfile.open ("c:\\desktop.txt");
// Attempt to open the named desktop
esktop = OpenDesktop("Winlogon", 0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
if(desktop!=NULL){
myfile << "desktop found.\n";
}else{
myfile << "desktop not found.\n";
}
HWND hwndCtrlAltDel = FindWindow("SAS window class", "SAS window");
if (hwndCtrlAltDel == NULL) {
myfile << "SAS window not found.\n";
hwndCtrlAltDel = HWND_BROADCAST;
}
PostMessage(hwndCtrlAltDel, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
HWND logonwindow = FindWindow("", "Log On to Windows");
if (logonwindow == NULL) {
myfile << "logon window not found.\n";
}
myfile.close();
|
|
|
|
|
|
Can any on tell me how to remove borders from a Combobox. I tried SetWindowRegion, it worked for Edit control, but it did not work with Combobox
Thanx
Md. Humayuon Kabir Hemoo
modified on Saturday, February 16, 2008 12:55 PM
|
|
|
|
|
You could try removing any border styles from the window styles associated with the
control.
If a control's painting implementation ignores the style then you have no choice but to draw
the control yourself.
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Thanks for your response. It seemes I need to draw the combobox my self. But don't you think SetWindowRegion should set the painting area of a control?
Humayoun
Md. Humayuon Kabir Hemoo
|
|
|
|
|
Humayun Kabir Hemoo wrote: But don't you think SetWindowRegion should set the painting area of a control?
Not necessarily. The control draws itself just like any other window.
Whether the control sets its own region or not, or honors any of the styles you
create it with, depends on the implementation.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I didn't know this before, thanx. By the way, removing WS_BORDER didn't work.
Md. Humayuon Kabir Hemoo
|
|
|
|
|
Do you want to customize combobox or remove border of it?
|
|
|
|
|
I want to remove the border.
Md. Humayuon Kabir Hemoo
|
|
|
|
|