|
|
Hello every1!
I am looking at some sample code that microsoft is giving out with MSDN and i can't understand what is going on...if some1 knows it...
Here's the problem - the project palmap(can be found in any MSDN library) is a dll file that is used as an extension of aviview(a prog for viewing avi files and also can be found in the MSDN). A part of the source of palmap.c says:
typedef struct {
IAVIStreamVtbl FAR * lpVtbl;
ULONG ulRefCount;
//
// instance data
//
PAVISTREAM pavi;
PGETFRAME pgf;
AVISTREAMINFO sinfo;
HPALETTE hpal;
LPBYTE lp16to8;
LONG lLastFrame;
LPBITMAPINFOHEADER lpdibLast;
} PALMAPSTREAM, FAR*PPALMAPSTREAM;
There is something sneaky in this struct since IAVIStreamVtbl is defined nowhere(i checked the headers and tried to see if any IDLs exist). I searched the whole project directory for that string and there is no match. It is obviously the vtable and also has an interface prefix but i don't find any interface definitions too. BTW: i tried to look for the definition by clicking with the right button on the "IAVIStreamVtbl" and choosing "Goto definition...." but there is no brosing files with that project. After building the project there are no errors or warnings. so - Where could this IAVIStreamVtbl be defined?
Thanks for any reply!
Vladimir Ralev
|
|
|
|
|
Hi, I'm hoping someone here can help me with a synchronization question.
I have a global function that adds entries to a log file. This function can be accessed by several threads in my program, and this function will also be used in different programs to write to the same log file. Because the log file is opened with the CFile::shareDenyWrite flag, I can only allow one thread to have access to this function at one time.
void WriteLog (LPCTSTR EntryString)
{
CMutex mutex(FALSE, _T("WriteLog - {AE4E28C0-84E6-11d5-B625-F80C283F7922}"));
CSingleLock lock(&mutex, FALSE);
while (lock.IsLocked());
lock.Lock();
COleDateTime dt = COleDateTime::GetCurrentTime();
CString LogEntry = dt.Format("%d/%m/%y %H:%M:%S - ");
LogEntry += EntryString;
CRotatingLog rl(_T("C:\\Bird_Log.txt"), 1000, 100);
rl.AddLine(LogEntry);
} As this is the first time I am using this method, I would like to know if this is the correct way of doing this, or will this just give me problems in the future? Is there a better way to wait for the CSingleLock object to unlock? The while loop seems to be very processor intensive. Any advice appreciated.
TIA
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
You can delete the 'while' loop. The default value of Lock method parameter is INFINITE, this means that CSingleLock::Lock will wait until mutex is released. This waiting will have no impact on CPU usage - it's implemented using ::WaitForSingleObject.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks, I'll try it;)
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
Does anyone know of any algorithms to convert degrees to pixels. I need to be able to rotate a bitmap by a given degree.
|
|
|
|
|
|
As degrees are an angular measure and pixels lateral the convertion would depend on how far from the rotation point you are. I have been playing with images for a while now and was going to write a lot of the code myself, but found it was better to concentrate on the rest of the project and do the image handling with a library written be someone who has more experience than I do. In the end I opted for ImgSource
http://www.smalleranimals.com/
It is inexpensive (note I don't say 'cheap') and does a very good job for what I need to do. Have a look it may do what you want.
Happy programming!!
|
|
|
|
|
Is there a way to understand if a port is listened by a server process on winsock ? If you know how to do this can you post a code sample.
Orcun Colak
orcuncolak@yahoo.com
|
|
|
|
|
What do you actually mean?!?!
You want a 'client' be able to test if a 'server/service' exist on a service-port over UDP?
UDP is a connectionless protocol, so the only way for the 'client' is to check the connection is waiting for any response on your message.
I write 'client' and 'server' between brackets, since client-server in UDP environment is not really a client-server architecture. With TCP/IP you split a socket when a connection is make (by listen -> accept), UDP doesn't do this, but you can use recvfrom to collect the others ip-address+port.
EiSl
|
|
|
|
|
I'm using CToolbar in an MDI w/ sliders,edits,comboboxes,etc.
And I need to place multiple rows of buttons for
one toolbar.I can make the toolbar wider, but I
don't know how to wrap the buttons on the toolbar
to make multiple rows.I've tried getctoolbarctrl(?)
but i can't get a wrap.
|
|
|
|
|
One of the examples on this site explaines the usage of multiple checkboxes in one 'placeholder' In stead of checkboxes buttons should be possible to. Be care full about keeping the GUI user friendly!
Give a yell if you need more help
EiSl
|
|
|
|
|
Does anyone know of a quick and easy way to encrypt / decrypt a phrase stored in a CString variable?
I'm looking for 40 bit (or lower) encryption that uses a hardcoded key for encryption / decryption.
Can anyone point me to a good resource, or give me some pointers?
Thanks,
Frank
|
|
|
|
|
You might try Wei Dai's Crypto++ library. It is:- easy to use,
- very C++ oriented,
- cross-platform,
- open source and royalty free.
There's an article on CodeProject with an example of use.
Regards,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I looked at Crypto++ and backed away from it for these reasons:
<l>
Way too much for what I need...I just need a simple encrypt/decrypt function.Import / Export restrictions. I think that 40 bit is cool with the US DOD, but i'm not exactly sure.
All I really need is a way to encrypt registration information for my app that is secure but at the same time not too difficult to implement. I've tried XoR and a few other "Simple" encrypt / decrypt methods but they dont seem to fit well into my scheme of things. If I could be specific, I'm looking for something that will give me an output similar to a PGP public key signature you would receive in an email.
Thanks for the suggestions,
Frank
|
|
|
|
|
But it's need to allow the writing only to my program.
Is it possible ???;)
|
|
|
|
|
When you crete the file, you must not put the otion shared
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
First, create your file, then:
SetFileAttributes(lpFileName, FILE_ATTRIBUTE_READONLY);
Of course i'm not sure ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Can a CRuntimeClasses be serialized using a CArchive. Can it be done by using code like this
CRuntimeClass *runtimeclass = RUNTIME_CLASS(CRandomClass)
ar << runtimeclass; or by
CRuntimeClass *runtimeclass = RUNTIME_CLASS(CRandomClass)
ar.WriteObject(runtimeclass); or is there another more complex solution?
Joel Holdsworth - the child eating devloper
'My cup of tea has caught fire!'
|
|
|
|
|
|
Hey folks,
I've been working on some code for some time which simply draws interconnecting boxes with text on the screen using the basic window calls to illustrate some kind of network connectivity. (Box represents a server, lines represent some kind of cabling between that server, and another).
For fun, I thought it would be great if I could implement some kind of "ZOOM" function which would change the sizes of the boxes dynamically, then choose a font which would fit in the new boxes.
I created a pull-down from the window I created, and added a resource for "10%", "25%", "50%", 100%", "200%", where 100% is the NORMAL view when you launch this window, 50% being half of the original etc, you get the idea.
When a user clicks on one of my "Zoom" items, I initialize a global variable called ZoomFactor which contains the ratio of how the diagram is to change. (ie. ZoomFactor == 1, denotes 100%, or normal view, ZoomFactor == 0.5, denotes half the original).
When the time comes to "build" the diagram again, I dynamically determine the new cell size by using the code below:
// Set our cellsize to be our zoomed cell size.
GetTextExtentPoint32 ( hdc, "A", 1, &szorgFontSize );
szZoomCellSize.cx = (LONG)(szorgFontSize.cx * ZoomFactor );
szZoomCellSize.cy = (LONG)(szorgFontSize.cy * ZoomFactor );
// Set the size of my server box width, by multiplying
// the new cell X size, by the maximum number of chars/server box.
ServerBoxWidth = szZoomCellSize.cx * MaxServerChars;
NO Problems, everything is great, my szZoomCellSize is scaled properly, my box sizes change as they should, Problem comes when I want to create an appropriate font for the new cellsize.
Basically, I want to create a font which will fit in the szZoomCellSize rectangle, I make this call in hopes that the font it creates will fit insize of the ZoomCell.
// Setup our new font
hfont = CreateFont ( szZoomCellSize.cy, 0, GM_COMPATIBLE, GM_COMPATIBLE, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_LH_ANGLES,
PROOF_QUALITY, FF_MODERN, lfnt.lfFaceName );
After I made this call, I noticed that in many cases, the font that it choose had a proportionate height and width (the font didn't look stretched), but was often TOO big for the box I've created. I added a "GetTextExtentPoint32" call after the create font and found that the font it picked was in most cases, LARGER than the "szZoomCellSize.cy" I specified. I understand that most fonts are NOT fixed width, so I even change the character in both "GetText" calls to "M", because M is usually one of the bigger characters, no go, same results.
I've spent some time looking through "CreateFont" and found it to be a little out of my league... By no means am I an expert graphics guy, just need a basic explanation! Anyone? Ive heard I can also create a bitmap of sorts, and just StrechBlt it, but I'm leaning NOT to do that...
Anybody see what I'm doing wrong here?
Much appreciated,
Mike.
|
|
|
|
|
First things first: you should negate the szZoomCellSize.cy. Details are in CreateFont docs
The second thing is that you're not guaranteed to get all character widths multiplied by X when you're scaling height by X. Scalable fonts can have hints and rendered bitmaps may have slightly different widths. You should just use DrawText with DT_END_ELLIPSIS flag to automatically display '...' if there's not enough space to display all characters in the box.
I've heard I can also create a bitmap of sorts, and just StrechBlt it, but I'm leaning NOT to do that
Don't StetchBlt. The algorithm used by this function is simple and fast - it doesn't perform any interpolations and resulting image looks ugly when scaling factor is not 2, 4, etc.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thomas,
Thanks for your reply.
I'm not quite sure what you mean by "negate", sounds silly and all, but do you mean put a "-" in front of my szZoomCellSize.cy?
hfont = CreateFont ( -szZoomCellSize.cy, 0, GM_COMPATIBLE, GM_COMPATIBLE, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_LH_ANGLES, PROOF_QUALITY, FF_MODERN, lfnt.lfFaceName );
I've made this change, and I'm still finding that the font its creating is larger than the HEIGHT I've specified. Is there a way or flag what would tell CreateFont to take the closest, lesser nHeight it can find?
In my code, everything revolves around the size of the font. Before I draw the text using the "ExtTextOut" with the ETO_CLIPPED option, I call "GetTextExtent32" to find out the average height and width of a characer. I then build a rectangle to which the text "should" fit. If the font "CreateFont" picks is larger than the box, then my rectangle and font will inevitably fall out of the box. You see my problem
By the way, I downloaded your screen saver app, great job...
Thx.
Mike.
|
|
|
|
|
I call "GetTextExtent32" to find out the average height and width of a characer.
Well, this is an average width. I think the best solution would be using DrawText instead of GetTextExtent32/ExtTextOut. You can use DrawText with DT_CALCRECT - in this case, nothing is drawn - the function calculates the rectangle needed to fit your string. So when user zooms in/out, you should create a font with given height, then paint all boxes using rectangle returned by DrawText called with DT_CALCRECT.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Have you tried using DrawText, seeing as you already have a rectangle in which you what the text to fit.
I am not too sure as to what this does to the actual font you have selected in the DC at the time, but I do know that there is a flag that will scale the text to fit in a given rectangle.
Hope this help
AndyC
|
|
|
|
|