|
As Max has pointed out, when it's a true/false case, it's recommended that you use bool and not BOOL . Worse is to use a BOOL and store integer values in it. Just like the MS people do.
Also to reply your OQ,
It's not a preference, you should always use
if(cond)
{
}
Rather than
if(cond==true)
{
}
Because with the later, there are chances you end up with the legendary "=" operator. like if(cond=true).
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Always try to use the first form.
Checking for equality with FALSE is theoretically ok, but you can end up in trouble if you compare it with TRUE. FALSE is always zero, but any other value is 'true'.
BOOL b = 3;
if (b) {}
if (b == TRUE) {}
shows the problem. (The first if fires, but not the second one)
My advice is to use the first form, which is more elegant, and always safe.
Also think about how you name your variables, and it will be easier to read the code.
|
|
|
|
|
Hallo!
I have Problems using DrawDibDraw (from msvfw32.dll) with Compression set to BI_BITFIELDS.
When I set biCompression to BI_RGB, it works, but when I set biCompression to BI_BITFIELDS, DrawDibDraw returns false and draws nothing.
Does anyone have any Ideas?
Here is my code:
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <vfw.h>
#define WIDTH 5000
#define HEIGHT 3000
short bits[HEIGHT][WIDTH];
BITMAPINFOHEADER * bmih;
int iCnt;
HDRAWDIB hdd;
int w,h;
RECT r;
int CDECL Xpress(TCHAR * msg,...)
{
TCHAR buf[1024];
va_list args;
va_start (args,msg);
_vsnwprintf_s(buf,sizeof(buf)/sizeof(TCHAR),msg,args);
va_end(args);
return MessageBox(NULL,buf,NULL,NULL);
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hwnd,&ps);
DrawDibDraw(hdd,hdc,0,0,w,h,bmih,bits,0,abs(500-iCnt%1000),w,h,DDF_JUSTDRAWIT);
EndPaint(hwnd,&ps);
return 0;
case WM_SIZE:
GetClientRect(hwnd,&r);
w=r.right-r.left;
h=r.bottom-r.top;
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmd,int nShow)
{
int iRet=-1;
for (int i=0;i<HEIGHT;i++)
{
for (int j=0;j<WIDTH;j++)
{
bits[i][j]=((i&0x1f)<<10)|((j&0x1f)<<5);
}
}
WNDCLASS cls;
cls.lpszClassName=L"WINDCLS";
cls.lpfnWndProc=WinProc;
cls.cbClsExtra=0;
cls.cbWndExtra=0;
cls.hbrBackground=NULL;
cls.hCursor=LoadCursor(NULL,IDC_ARROW);
cls.hIcon=NULL;
cls.lpszMenuName=NULL;
cls.hInstance=hInst;
cls.style=0;
r.top=0;
r.left=0;
r.right=GetSystemMetrics(SM_CXSCREEN);
r.bottom=GetSystemMetrics(SM_CYSCREEN);
if (RegisterClass(&cls))
{
HWND desk = CreateWindowW(L"WINDCLS",L"Main",WS_SYSMENU,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInst,NULL);
ShowWindow(desk,nShow);
UpdateWindow(desk);
bmih=(BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER)+3*sizeof(DWORD));
bmih->biSize=sizeof(BITMAPINFOHEADER)+3*sizeof(int);
bmih->biWidth=WIDTH;
bmih->biHeight=HEIGHT;
bmih->biPlanes=1;
bmih->biBitCount=16;
bmih->biCompression=BI_RGB;
bmih->biSizeImage=WIDTH*HEIGHT*2;
bmih->biXPelsPerMeter=0;
bmih->biYPelsPerMeter=0;
bmih->biClrUsed=0;
bmih->biClrImportant=0;
DWORD * col = (DWORD *)&bmih[1];
col[0]=0xFC00;
col[1]=0x03E0;
col[2]=0x001F;
MSG msg;
hdd = DrawDibOpen();
if (hdd==NULL)
{
Xpress(L"Cant get DIB");
}
else
{
long start = GetCurrentTime();
for (iCnt=0;iCnt<10000&&GetMessage(&msg,NULL,0,0);iCnt++)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
bits[1500+iCnt/500][iCnt%500]=0x1f;
InvalidateRect(desk,&r,FALSE);
}
DrawDibClose(hdd);
Xpress(TEXT("%i fps"),1000*iCnt/(GetCurrentTime()-start));
iRet=(int)msg.wParam;
}
}
return iRet;
}
Many thanks...
Uwe
|
|
|
|
|
I am trying to access a c++ created DLL from within Excel, with semi-success only:
I've followed the following tutorial EXACTLY: http://newtonexcelbach.wordpress.com...ng-excel-to-c/
Now, when I try and use the dll-functions that I've declared in the VB code, the function GetPrice(), which takes no arguments and simply returns a number, works fine.
However, as soon as I create a dll-function which takes input arguments, I get a #VALUE error in the cell in Excel ("A value used in formula is of the wrong data type" ).
I've downloaded the complete sample from the URL above and get the same error when running it (after recalculating the formulas).
I've created a test 'proxy' function (in which the code can be stepped through, which calls the dll function) to ensure that values sent to the dll function are indeed of type double and that seems to be the case ...
This guy seems to have had the same problem, however no solution was posted:
http://www.ozgrid.com/forum/showthread.php?t=54245[^]
Any help / tips would be greatly appreciated!
g
excell dll newbie
|
|
|
|
|
I can tell you one thing as a tip ... DON'T CROSS POST IN FORUMS !!!!! Find the best forum, post the message ONCE !!!!
'g'
|
|
|
|
|
Sorry but I don't know which forum is best for this one ( ? )
|
|
|
|
|
this one c/c++/MFC ..
'g'
|
|
|
|
|
so, did you see the discussion following the article where people were talking about 'deployment' and the VS2008 redistributables, the location of the dll etc ?? - any differences ?
'g'
|
|
|
|
|
No I didn't see that ?
This is such a weird problem. Don't get why it would work for everyone else but not for me ...
|
|
|
|
|
gvanto wrote: Don't get why it would work for everyone else but not for me ...
ahh, but it didnt work for everyone - go back the page, read down past the initial steps - others did have issues and (may have) fixed them
'g'
|
|
|
|
|
Hmmm that was a bit schoolboy of me not to spot that error, thanks Garth!
I've actually just built the same functionality in a C# dll, works like a bomb!
Now I have a little design problem: I'd like the function I call in the dll to KEEP a cell dynamically updated (it fetches a security's price
from a local db).
Two options:
1) Loop within excel and keep calling the dll function (which queries the db and returns the result)
2) Loop within the dll and *somehow* keep the value of the cell WHICH CALLED IT, up to date. (this is how bloomberg's API functions to keep excel cells dynamically updated, very nifty !
I'm thinking that efficiency-wise, 2) would be better (something tells me that having 200 cells repetitively calling a function will cause Excel to hang ... is my hunch correct?)
Best,
G
|
|
|
|
|
PS: I dont have admin rights on this machine else I'd give the VS2008 redistro stuff a go, sure sounds like it could work ...
|
|
|
|
|
Im sure there are other people out there who can answer that one better than I can ...
'g'
|
|
|
|
|
Hi All,
I created a MSI with help of wise installer with merg modules option.
When i installed my application on client machine, the application is not able to get the MFCVC90.dll and MSVCR90.dll.
The wise installer is copying these files to
WinSxS\XXXXX\XXXX folder.
How can i make sure that wise copies these dll's to system32 for my application to run without problems.
Regards,
Ramchandra
Ramchandra
|
|
|
|
|
Hi ,
I am a beginner but I would like to learn.
I would like to use a new thread to read some data with an USB-module and to print it out in a CViewForm.
Now I have a total working program that can read and print when I click on the start button, but an infinit loop under the startbutton is written to read data until I click on Stop.(the data is real-time printed on the screen in a graph) This ofcourse is not possible because I stay in the loop under the startbutton. I can't click anything.
This logic problem I want to solve with strating a new thread just for collecting data from the USB-module and printing a graph on screen.
Now to use my old program is it possible to make an extra class derivaded from CWinThread and just call or postmessage the CView and CDocument members or functions ? If I could use my CView and CDocument members and functions in the InitInstance I thing I have a solution.
Maybe I am totaly wrong , I am just a beginner
Thanks a lot (sorry for my English)
|
|
|
|
|
Piction wrote: I am a beginner but I would like to learn.
Then I strongly suggest you obtain and read learning materials specifically designed for beginners rather than posting things into internet forums.
|
|
|
|
|
Howdy everyone...
Could someone help me? I'm trying to write an algorith tht returns all the possibilities of the letters in a string, that starts at the initial word, then works its way down to all comniations of 2 letters.
To say it another way... if I have "ABCDEF", the function will return "ABCDEF" first (as there is only one of these), then return 6 strings of 5 letters each ("ABCDE", "BCDEF", "ACDEF", "ABCDF", "ABDEF" and "ABCEF"), as only 6 exists, then return 15 strings of 4 letters each, then 20 of 3 each, 15 of 2 each, and stop.
C++ or C# or just an idea of how to accomplished this would be great.
Thank you so much,
Michael
== // ==
BlueCoder
|
|
|
|
|
Use a bucket for every other letter in the alphabet. Then every letter you trip over, pour it into the right bucket.
|
|
|
|
|
led mike wrote: Use a bucket for every other letter in the alphabet. Then every letter you trip over, pour it into the right bucket.
You mean like A C E G I, etc., then I lost you?
What about the 'even' letters?
Michael
== // ==
BlueCoder
|
|
|
|
|
By 'bucket' I think he means an array of integers where each entry represents one of the letters of the string. "Pooring into the right bucket" means incrementing the count of that letter's entry in the array.
That was a good hint but I think it is best that you figure it out from there. 
|
|
|
|
|
Do you recommend the boost version of a bucket or the MFC version ?

|
|
|
|
|
Thanks Rick...
Either one, if that was a question to me.
Michael
== // ==
BlueCoder
|
|
|
|
|
No, sorry. My reply was an attempt at a bad joke aimed at led mike.
|
|
|
|
|
I thought that, just after I posted.
== // ==
BlueCoder
|
|
|
|
|
Yes I failed in resisting the urge to have a go at this student 
|
|
|
|
|