|
what is the best way to resize a structure during run time. I have a struct that rights out a record to a file. Now I will have 2 scenarios that that requires that one of the fields in the middle of the struct be a different size. All the fields in the struct are char or char[]. can this be done with unions? I have code in place that does all the formating, so I don't want to have to rechange everything.
|
|
|
|
|
A struct should always have the same size and never be resizable. If you have the need to store items of an unkown size, store the pointer/offset to the data in the struct and write the data where the struct can find it.
For example:
struct MyStruct
{
DWORD szText;
char szSoreText[ 28 ];
struct UnknownStruct
{
...
}
} foo;
When writing this to a file you would set the szText to sizeof( MyStruct ) . This indicates that the string is stored right after the struct. To get the text you would do something like:
char* szStructsText = (char*)( &foo + foo.szText );
Waldermort
|
|
|
|
|
Resizable structure is not possible.
If u r using C++ then u can derive new structure from existing one like class..
ThankXXXX..
|
|
|
|
|
Hi,
I know there are a few good articles regarding driver development here, but unless I missed it, I couldn't find something about sending an asynchronous IOCTL from user space to kernel.
Any help or link would be great.
|
|
|
|
|
When you open the device, you need to specify that you will be doing overlapped I/O. Then, when calling DeviceIoControl, use the overlapped parameter.
Judy
|
|
|
|
|
Hi there,
Just inherited some VC++ code from a colleague, including .cpp,.CPP,.h,.H, i know nothing about Visual C++, but I was told the program was executable.......my silly questions are:
1) .cpp and .CPP the same ?
2) How to build them into one project to make it executable using Visual Studio 2005?
I couldn't find the straightforward answer from the Internet.
Any hint? Many thanks.
Regards,
Aloha
|
|
|
|
|
Aloha2007 wrote: Just inherited some VC++ code from a colleague, including .cpp,.CPP,.h,.H,
What version of VS was s/he using?
Aloha2007 wrote: 1) .cpp and .CPP the same?
Yes.
"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
|
|
|
|
|
Hi David,
Many thanks for reply.
He use Visual Studio 2003 or even earlier version.
The built-up project was executable in 2003 version, but when run it on 2005 version, it says: the project is out of date.
Then I asked for the original codes, but don't know how to build it on Visual Studio 2005.
Regards,
Aloha
|
|
|
|
|
You can make a project and insert your codes on that project.(Ctrl+Shift+N) after press these buttons you see a window that you can select project type select MFC then MFC Application.
|
|
|
|
|
Does MFC provide any method which will give me a list of handles or pointers to ALL open documents or MDI child windows in an MFC MDI Doc/View application?
Thanks
|
|
|
|
|
The CDocTemplate objects keep track of open documents. By iterating through the
registered templates, you can get the open docs associated with each template.
For enumerating views, you can do it the windows way(s) like EnumChildWindows()
or you could also use CDocument::GetFirstViewPosition()/CDocument::GetNextView()
to get the views for each document obtained as described above.
For an example of enumerating documents, you can check out the source code.
CWinApp::CloseAllDocuments() is an example.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Great! Using CDocTemplate::GetFirstDocPosition and CDocTemplate::GetNextDoc, along with CDocument::GetFirstViewPosition and CDocument::GetNextView, I was able to get everything I needed.
Thanks very much!
|
|
|
|
|
Hi
when i compile this:
#include <windows.h>
#include <mapiwin.h>
typedef struct _INST
{
UINT cRef;
LPMALLOC lpmalloc;
} INST, *PINST;
int main()
{
PINST pinst;
pinst = (PINST) PvGetInstanceGlobals();
return 0;
}
i get
Linking...
testmapiWin.obj : error LNK2001: unresolved external symbol _pinstX
Debug/testmapiWin.exe : fatal error LNK1120: 1 unresolved externals
pinstX is defined in MAPIwin.h
extern LPVOID pinstX;
dose any one have a idea why this won't compile...
Many Thanks
Calvin
|
|
|
|
|
Try adding this to your source code, in some *.cpp file
#pragma comment(lib,"mapi32.lib")
|
|
|
|
|
thanks
I tried that and stil got the same error
is this the same as adding mapi32.lib to the linker "additional dependancies" as i all ready have it added there.
Many Thanks
Calvin
|
|
|
|
|
Ok...
Did some reading and found out what was going on..
The key is that "pinstX" is defined in "MAPIWIN.H" as "extern LPVOID pinstX;" the key is the "extern" which is apaerntly a external global so all I had to do was add..
LPVOID pinstX;
to the main file (or main header) and now it compiles..
so it now reads
#include <windows.h>
#include <mapiwin.h>
LPVOID pinstX;
//typedef LPVOID pinstX;
/* Per-instance data. */
typedef struct _INST
{
UINT cRef;
LPMALLOC lpmalloc;
} INST, *PINST;
int main()
{
PINST pinst;
pinst = (PINST) PvGetInstanceGlobals();
return 0;
}
Many Thanks
Calvin
|
|
|
|
|
Calvin Streeting wrote: extern LPVOID pinstX;
dose any one have a idea why this won't compile...
Your code compiles fine. It's the linker that is complaining. By using the extern keyword, you've told the linker that the actual declaration of pinstX is found in some other .obj file. Guess what: the linker could not find it.
"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
|
|
|
|
|
hi all
I want to add a hotkey (shortcut key) s.t. when pressing alt+control+shift+p it would do something
(start ms-word with my private diary I tell my self all sorts of thins there....shhhh...)
I tried to make this shortcut keys from a desktop icon but it seems that it stopped working after a few booting of my computer.
anyway I want to succeed in that method of hot key ive been tring to do a little in c++(no mfc) program to add a hotkey using registerhotkey and the message WM_HOTKEY:
but it dont work for me at all (it seems that the shortcut keys dont activate the message WM_HOTKEY)
any help?
thanks
(ive followed the directions in this article
http://www.codeproject.com/system/nishhotkeys01.asp[^][^]
)
here is the abreviated source code of the little program for a hotkey:
int WINAPI WinMain (...){
.
.
.
RegisterHotKey(hwnd, 100, MOD_ALT | MOD_SHIFT | MOD_CONTROL , 'p');
.
.
.
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
string execstr;
execstr = ("\"C:\\Program Files\\Microsoft Office\\Office10\\WINWORD.EXE\" \"C:\\Documents and Settings\\DELL\\My Documents\\diary.jjj\"");
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_HOTKEY:
printf ("pressed hotkey");
WinExec (execstr.c_str(),SW_SHOW);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
|
|
|
|
jokop wrote: but it dont work for me at all (it seems that the shortcut keys dont activate the message WM_HOTKEY)
Did you check the return value of RegisterHotKey() ?
Is WindowProcedure() receiving any messages?
"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
|
|
|
|
|
use the following code
RegisterHotKey(hwnd, 100, MOD_ALT | MOD_SHIFT | MOD_CONTROL , 0x50);<br />
intstead of
RegisterHotKey(hwnd, 100, MOD_ALT | MOD_SHIFT | MOD_CONTROL , 'p');<br />
It requires the ASCII in the last argument. and tell me whether it worked or not.
|
|
|
|
|
thanks very much
it works now.
now I have another minor problem:
I want to run this program all the time and I dont want any window of the program to be shown (even as minimized) but the cmd window is present as long as the program is running.
|
|
|
|
|
Can anyone help me with building a toolbar with two vertical columns?
Mark
|
|
|
|
|
Mark_VC wrote: Can anyone help me with building a toolbar with two vertical columns?
Depending on what you need, I can think of a couple ways. One is to just use two toolbars. Another option is to use a "dialog bar" and make the dialog template provide two vertical columns of buttons.
Nathan
|
|
|
|
|
I would really like toolbar by itself so that the program looks professional. I may use calcFixedlayout. If you have a neat way how to do it, please do help.
thanks.
|
|
|
|
|
Mark_VC wrote: I would really like toolbar by itself so that the program looks professional. I may use calcFixedlayout. If you have a neat way how to do it, please do help.
thanks.
I'm afraid I don't understand what your saying. How would a dialog bar look nonprofesional?
Nathan
|
|
|
|