|
Vaclav_Sal wrote: refuses to give me the whole text of the selected item
How did you verify that? Through debugging? Try putting a message box. If _UNICODE is define in your project, you must set some settings of MSDEV.
tools->options->Debug-> Now tick the "Display UNICODE string check box".
|
|
|
|
|
Nave,
I changed to display UNICODE and it works now. However I am using MS sample code and did not find UNICODE defined!
Thanks for your help
|
|
|
|
|
Vaclav_Sal wrote: and did not find UNICODE defined!
Check the following location.
project settings->C++->And in the Preprocess definitions edit box check _UNICODE is defined.
|
|
|
|
|
You are absolutely correct!
Thanks
|
|
|
|
|
Hi all:
When I am trying to write the function definition for:
OccurrenceList& getOccurrences(string word);
I wrote:
<code>......
typedef vector<streampos> OccurrenceList;
......
78: OccurrenceList& WordTable::getOccurrences(string word) {
79: OccurrenceList list;
80: return list; //Return nothing to simplify the function for debugging.
81: }</code>
But I have 5 (!!) errors, they are:
78: error C2143: syntax error : missing ';' before '&';
78: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int;
79: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int;
79: 'int &WordTable::getOccurrences(std::string)' : overloaded function differs only by return type from 'WordTable::OccurrenceList &WordTable::getOccurrences(std::string)';
79: 'WordTable::getOccurrences' : redefinition; different basic types;
When I commented out this function, the rest of my program ran sweet. I really do not know what caused those problems.
Thank you
|
|
|
|
|
It looks like the compiler doesn't know what a "OccurrenceList" type is at that point.
Are you missing a header file containing the declaration of the class?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi:
That IS the problem.
Thank you
|
|
|
|
|
Hello,
I would like to wrap VC++6 code; it should be used at C# calss (all at VS2005).
Do you know how to do it? Do you have any example?
thanks.
|
|
|
|
|
I guess this is a pretty well trodden route.
First port your VC6 C++ to VC8. The project will auto convert but you still need to tidy up all the Safe CRT change consequences to get rid of W4 Warnings. Make sure it all works with the new MFC/ATL etc.
Second if the substance of your C++ is not in COM objects, you may be in a deal of trouble. Fortunately it's not usually hard to start chunking your C++ into COM objects, depending on how big it is.
Third, once you've got the code you want to use in one or more C++ COM objects take a look at articles on C# COM Interop. It works really well once you get over the inital strangeness, doesn't require you to write a lot of code or even any PInvokes or proxy/stub nastiness.
Step four is probably to move this post to the C# Managed and mixed development forum before somebody moans;)
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
if you can put your code in a C-interfaced DLL, you can use it from C# (or any language, really) without too much hassle.
|
|
|
|
|
I agree with Chris Losinger Dll is a good choice.
|
|
|
|
|
When I compile this code in MSVC++ 2005 express I get the following error.
SERVICE_TABLE_ENTRY DispatchTable[]=
{{"Service1",serviceMain},{NULL,NULL}};
error C2440: 'initializing' : cannot convert from 'const char [9]' to 'LPWSTR'
Pretty much where ever I am using a string I get the same error. Why doesn't the code work?
|
|
|
|
|
I would have to see the definition of SERVICE_TABLE_ENTRY to be sure but I suspect it's defined to contain a wide character (UNICODE) string whereas "Service1" is a constant narrow character or (ASCII) string. UNICODE strings, usually, have 16bits per character while ASCII characters have only 8bits each so conversion between the two is non trivial. There's a whole world of pain involved here, code pages, locales, W2A macros, multi-byte character sets, UTF-8 and then some but what you need to do to make the above code work is make use of the _T() macro Microsoft so kindly supply.
SERVICE_TABLE_ENTRY DispatchTable[]=<br />
{{ _T( "Service1" ) , serviceMain }, {NULL, NULL}};
Enjoy.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Add L before "", it declare it as wide char.
<br />
SERVICE_TABLE_ENTRY DispatchTable[]=<br />
{{L"Service1",serviceMain},{NULL,NULL}};<br />
Best Regards.
|
|
|
|
|
Anybody see what the problem is with this code? GetDIBits fails, and when I call GetLastError(), it tells me that Windows "ERROR_FILE_NOT_FOUND".
<br />
<br />
GetClientRect(hDlg, &rc);
<br />
hdc = GetDC(hDlg);
<br />
rc.bottom -= (GetSystemMetrics(SM_CYHSCROLL)+GetSystemMetrics(SM_CYEDGE));<br />
<br />
hSavedXYContext = CreateCompatibleDC(hdc);
hSavedXYBitmap = CreateCompatibleBitmap(hdc, rc.right-rc.left,rc.bottom-rc.top); <br />
<br />
hTheDCsOriginalBitmap = (HBITMAP)SelectObject(hSavedXYContext, hSavedXYBitmap); <br />
<br />
BitBlt(hSavedXYContext,0,0,rc.right-rc.left, rc.bottom-rc.top,hdc,0,0,SRCCOPY);<br />
<br />
hSavedXYBitmap = (HBITMAP)SelectObject(hSavedXYContext, hTheDCsOriginalBitmap); <br />
<br />
<br />
<br />
<br />
<br />
GetObject(hSavedXYBitmap,sizeof(BITMAP),(LPSTR)(&bmp));<br />
<br />
cClrBits = (WORD)(bmp.bmPlanes*bmp.bmBitsPixel);<br />
<br />
cClrBits = 4;<br />
<br />
pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFOHEADER));<br />
<br />
<br />
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
pbmi->bmiHeader.biWidth = bmp.bmWidth;<br />
pbmi->bmiHeader.biHeight = bmp.bmHeight;<br />
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;<br />
pbmi->bmiHeader.biBitCount =4;<br />
<br />
pbmi->bmiHeader.biCompression = BI_RGB;<br />
<br />
pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 15)/16 <br />
* pbmi->bmiHeader.biHeight * 4;<br />
<br />
pbmi->bmiHeader.biClrImportant = 0;<br />
<br />
<br />
pBitmapInfoHeader = (PBITMAPINFOHEADER)pbmi;<br />
<br />
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED,pbmi->bmiHeader.biSizeImage);<br />
<br />
test = GetDIBits(hdc,hSavedXYBitmap,0,(WORD) pbmi->bmiHeader.biHeight,<br />
lpBits,pbmi,DIB_RGB_COLORS);<br />
<br />
test = GetLastError();<br />
I would appreciate any feedback, as I am out of ideas.
|
|
|
|
|
You have to check all the values passed to GetDIBits very carefully. That functions is very touchy and will fail if a single bit is not correct. I do not think the error message has anything to do with the code you are showing, as GeDIBits will often fail without generating any error at all.
See CDibData[^], it might help.
Note: CDibData has a minor bug that I still have not updated, but it has been a while since I played with graphics.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I see a few problems -
TheDelChop wrote: GetObject(hSavedXYBitmap,sizeof(BITMAP),(LPSTR)(&bmp));
Irrelevent, but cast to a LPSTR?? No cast to a void pointer is necessary
Problems:
Creating a BITMAPINFO the size of a BITMAPINFOHEADER.
Using the planes value from the DDB when it HAS to be 1 in a DIB.
bmiHeader.biSizeImage is calculated wrong - rows of pixel data in a DIB need to be DWORD aligned.
You've provided no color table (16-colors) for your destination 4-bit DIB
The resulting GetDIBits call should fail based on the above.
Something like this maybe will get you closer:
...
int nNumColors = 1 << cClrBits;
LONG lBytesPerRow = (((bmp.bmWidth * (long)cClrBits + 31L) & (~31L)) / 8L);
BYTE* pBitmapBits;
LONG SizeOfBitmapInfo = sizeof(BITMAPINFO) + ((nNumColors - 1) * sizeof(RGBQUAD));
BITMAPINFO *pbmi = (PBITMAPINFO) LocalAlloc(LPTR, SizeOfBitmapInfo);
memset(pbmi, 0, SizeOfBitmapInfo);
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = lBytesPerRow * bmp.bmHeight;
pBitmapInfoHeader = (PBITMAPINFOHEADER)pbmi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED,pbmi->bmiHeader.biSizeImage);
test = ::GetDIBits(hdc, hSavedXYBitmap, 0, (WORD) pbmi->bmiHeader.biHeight, lpBits, pbmi, DIB_RGB_COLORS);
if (test == 0)
test = GetLastError();
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I want to compile a project that I have created. The project has class objects separated in different files i.e. main.cpp, card.h, card.cpp, deck.h, deck.cpp. How am I able to do this so the deck class can create in instance of the card class i.e. vector<card*> x; I know this is really newbie but I got to know.
|
|
|
|
|
joshp1217 wrote: How am I able to do this so the deck class can create in instance of the card class
class deck
{
deck();
~deck();
card c;
} Or you can do it in one of the deck 's members:
void deck::foo( void )
{
card c;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Remember to make sure that all the files that use a type ( e.g card class ) have a #include line that references the file that defines the type.
If card is defined in card.h then deck.cpp might look something like this.
<br />
<br />
#include "card.h"<br />
<br />
<br />
deck::deck()<br />
{<br />
card the_cards[52];
}<br />
If the definition of deck itself, in deck.h, depends on the definition of card then it's deck.h that should #include "card.h"
Think of it as, when the compiler sees #include "card.h" it goes and reads the card.h file and after that it knows about the card class otherwise it's as if it never heard of it.
The trick is that every time it moves on to compiling a different .cpp file (compilation unit) it forgets everything it found out before and starts again knowning nothing except C++. Sounds dumb but it really works
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I thought that was how it should work but when I sent it up that way, i was getting errors like the Deck class didnt recognize the Card class because when i said vector<card*> m_Cards;(this is in the deck.h with #include "card.h" at the top) it basically would say that a vector cant have any empty type. The IDE i am using is Dev-C++ I dont know if that has anything to do with it but any further help would greatly be appreciated because I could do this with ease in C# but I need to do it in C++.
|
|
|
|
|
Should that perhaps be vector<card> m_Cards; or did the html formatter just make your vector type parameter disappear? If not it might explain the empty type error, might even need #include<vector> and std::vector<card>m_Cards;
There's very little of the using AClass::BClass; stuff in C++ although
using namepsace std; works just fine and should let you use a vector as per the first example above. I'm no STL guru but then if you've done loads of C# you're no newbie either
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
This Code fails on XP 64 bit even if the file exists in the target folder
The exe is 32 bit
CString str;
str = "C:\\WINDOWS\\system32\\drivers\\acpi.sys";
if(!PathFileExists(str))
{
}
i can paste any file in that folder (text file or whatever) and the result will be file not found (errcode=2)
it shows same behaviour in "c:\windows\system32" folder
So is there some security issue i am not seeing cause this thing runs fine in vista with UAC enabled
Thanks
|
|
|
|
|
|
Good to know! Thanks for the update!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|