|
userName[100]=(TCHAR) SendMessage(hwndedit,WM_GETTEXT,(WPARAM)sizeof(userName)/sizeof(userName[0]),(LPARAM)userName);
You are casting your return value to a single character and storing it in one character position beyond the end of your buffer. You should just use GetWindowText like this:
int nSize = GetWindowText(hwndedit, userName, _countof(userName));
See GetWindowText function (Windows)[^] and _countof Macro[^].
|
|
|
|
|
|
The default context menu (in explorer and open file dialogs) looks like the image below:
The selected menu item has a dark gray background, and I don't like it. It can't be replaced by the theme.
I want to restore its style to Windows 8/8.1 style, like this(Windows 10 earlier insider builds):
I have programmed a COM dll and attach it to the explorer, it's able to retrieve the handle of the context menu, but I discovered that none of those menu items have the "MF_OWNERDRAWN" flag, they just have "MF_STRING" flag.
So things start to getting wired, perhaps they are not normal owner drawn menus?
My question is how does the explorer render its context menu? And are there anyway to customize its style? eg using hook?
|
|
|
|
|
I've been recently asked in an interview to write down a function that takes a char and returns void, and using this char the function would call between 5 different functions,
Beside I have to write this function in three different ways.
I figured out two, but failed to come with the third.
My two functions were : 1- using switch on the coming argument
2 - using if else statements
,, can some 1 deduce the third , this is bugging me.
|
|
|
|
|
Here's an idea:
Use the char as an array index for an array of function pointers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
alright I like this one
|
|
|
|
|
Hi,
I need to check from a dll that If a particular driver is already installed or not. Also i need to un-install it.
I have INF file of the driver.
Please let me know how can i do this using C/C++.
Thanks
Prasanth
|
|
|
|
|
|
Am creating application and l need to fill a combo box list. However, l was able to do all and is working but whenever l filling the last combobox, l get an exception as below.
First-chance exception at 0x7789dba9 in Unical PTUME.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x7789dba9 in Unical PTUME.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
What does it mean and how can l correct it?
code snippet below:
case WM_CREATE:
DialogBox(((LPCREATESTRUCT)lParam)->hInstance, MAKEINTRESOURCE(IDD_CHOICEBOX),hWnd,choicedlg);
return 0;
INT_PTR CALLBACK choicedlg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
int i=0; static int firsttime=1; PWSTR input=NULL;
switch(message)
{
case WM_INITDIALOG:
for(i=0; i<=sizeof(Choice)/sizeof(Choice[0]); i++){
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_FACULTY,CB_ADDSTRING,0,(LPARAM)Choice[i]);
}
for(i=0; i<=sizeof(Course)/sizeof(Course[0]); i++){
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT1,CB_ADDSTRING,0,(LPARAM)Course[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT2,CB_ADDSTRING,0,(LPARAM)Course[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT3,CB_ADDSTRING,0,(LPARAM)Course[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT4,CB_ADDSTRING,0,(LPARAM)Course[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT5,CB_ADDSTRING,0,(LPARAM)Course[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_SUBJECT6,CB_ADDSTRING,0,(LPARAM)Course[i]);
}
for(i=0; i<=sizeof(Year)/sizeof(Year[0]); i++){
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR1,CB_ADDSTRING,0,(LPARAM)Year[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR2,CB_ADDSTRING,0,(LPARAM)Year[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR3,CB_ADDSTRING,0,(LPARAM)Year[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR4,CB_ADDSTRING,0,(LPARAM)Year[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR5,CB_ADDSTRING,0,(LPARAM)Year[i]);
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_YEAR6,CB_ADDSTRING,0,(LPARAM)Year[i]);
}
However, if l add the code below, l always get error message as above.
for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++){
SendDlgItemMessage(hwnd,IDC_UNICALPTUME_TIME,CB_ADDSTRING,0,(LPARAM)Time[i]);
}
modified 18-Jan-16 17:12pm.
|
|
|
|
|
What is the value of Time[i] when the code runs?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
All your for loops are iterating from 0 to (including) sizeof(array)/sizeof(array[0]) :
for(i=0; i<=sizeof(Time)/sizeof(Time[0]); i++)
So they will access one item behind the array size with the last iteration because the max. allowed index is the number of items minus one.
Change all your loops to use < rather than <= (here for the last one):
for(i=0; i<sizeof(Time)/sizeof(Time[0]); i++)
|
|
|
|
|
@Jochenn Thanks, l made the corrections and it worked.
|
|
|
|
|
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
int main(int *op[]) {
char n;
int total;
int ct = 0, oper1 = 0, oper2 = 0, oper3 = 0, i = 0;
FILE *arq1;
arq1 = fopen("Maq1.log", "r");
while (!feof(arq1)) {
n = fgetc(arq1);
if (n == "\n") {
ct++;
}
}
op = (int*) calloc(ct, sizeof(int));
if(op==0) {
printf("Não houve memoria alocada!\n");
return 0;
}
for(i=0;!feof(arq1);i++) {
fscanf(",,,%d,", &op[ct]);
}
for(i=0;i<=ct;i++) {
if(op[ct] == 1){
oper1++;
}
if(op[ct] == 2){
oper2++;
}
if(op[ct] == 3){
oper3++;
}
}
total = oper1 + oper2 + oper3;
printf("Operacao 1: %d \n Operacao 2: %d \n Operacao 3: %d \n Total: %d \n", oper1, oper2, oper3, total);
fclose(arq1);
return 0;
}
Can you guys help me on this Code? I have no idea of what is happening, but when I run the code he prints
Operacao 1: 0
Operacao 2: 0
Operacao 3: 0
Total: 0 Sorry for the bad english!
modified 13-Jan-16 15:05pm.
|
|
|
|
|
Have you tried stepping through the code using a debugger?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
gcc -c "trabalho.c" -o "trabalho.o"
trabalho.c: In function ‘main’:
trabalho.c:22:11: warning: comparison between pointer and integer
if (n == "\n") {
^
trabalho.c:35:5: warning: format ‘%d’ expects argument of type ‘int *’, but argument 3 has type ‘int’ [-Wformat=]
fscanf(arq1, ",,,%d,", op[ct]);
^
g++ -o "trabalho.o"
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 2 warning(s) (0 minute(s), 0 second(s))
Checking for existence: /home
Executing: xterm -T 'dest" (in origem)
Process terminated with status 0 (0 minute(s), 2 second(s))
When I compile the .c archive, appears just those 2 warnings
|
|
|
|
|
The three if() conditions in your for() loop are always looking at op[ct] rather than op[i] . I do not think that is your intent.
A date with the debugger, as jeron1 suggested, would have unveiled that.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thank you! I didn't see that error of logic... --'
But still giving me the same answer :/
I think the error is when he count the lines on
char n;
while (!feof(arq1)) {
n = fgetc(arq1);
if (n == "\n") { ct++;
}
}
warning: assignment makes pointer from integer without a cast
and...
for(i=0;!feof(arq1);i++) {
fscanf(arq1, ",,,%d,", op[i]); }
format ‘%d’ expects argument of type ‘int *’, but argument 3 has type ‘int’ [-Wformat=]|
|
|
|
|
|
honor3us wrote: if (n == "\n") { Why are you not using:
if (n == '\n')
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Another error, sorry :/
I changed to 'n' and &op[i] and all the warnings are gonne!
The programs runs perfectly but all the values of vector op[] are == 0.
ex:
printf("%d\n%d", op[4], op[5]);
The answer still
0
0
I'm really thankful!
|
|
|
|
|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
This has nothing to do with the solution to your problem, as DavidCrow has already given you a clue. I'm just wondering if your compiler isn't giving you any warnings about your definition of main().
int main(int *op[]) definitely isn't one of the normal ways to define main() Normally it would be one of
int main()
int main(void)
int main(int argc, char *argv[])
int main(int argc, char **argv)
On some systems you might also be able to use int main(int argc, char *arg[], char *envp[])
Note that as a function parameter char *arg[] and char **arg are equivalent.
You also have a type issues with op . It's declared as int *op[] , which is an array of pointer to int, but you are using it as a pointer to int. What you probably want to do is:
int main(void)
{
...
int *op;
op = (int*)calloc(ct, sizeof *op);
...
}
If you're wondering why I used sizeof *op as the second argument to calloc() , consider what might happen if you decide you want to change op from an int to a long , and what might happen if you forget that you need change the call to calloc() too.
|
|
|
|
|
Thank you! You help me a lot!
But the compiler still having problem to count lines and fscanf the data I need, I don't have a clue what is going on--'
|
|
|
|
|
You might want to look at this section of the code ... there's definitely an issue here:
for( i=0; i<=ct; i++) { if(op[ct] == 1){
oper1++;
}
Also, you are accessing past the end of the array op[] -- what should the end condition for the loop be?
|
|
|
|
|
The program is working fine now, just needed to close the file and open again to read the data.
Ty for the help everyone!
|
|
|
|
|
honor3us wrote: ...just needed to close the file and open again... Or call rewind() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|