|
The Problem is called struct member alignment.
see msdn : struct member alignment
the compiler inserts extra bytes to optimize it for a cpu.
the standard alignment is 8.
To make your code work, you have to insert
#pragma pack( push, 1)
struct
{
//..
};
#pragma pack(pop)
the pragma enables aligment of 1 byte.
This is not a good way to solve your problem.
You better insert 2 methods to read/write your struct memberwise.
This is called serialisation.
|
|
|
|
|
What does the test.dat file look like? How are you verifying that packet.head1 and packet.head1 do not contain the correct values?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I've implemented a wizard using the CPropertySheet and CPropertyPage classes.
When i'm in a particular page of the wizard, when i click the "Cancel" button or press ESC or close the page by clicking on the "X" in the right top corner, the CANCEL message gets fired and control comes to the OnCancel command handler. At this point the PSN_WIZFINISH notification is not sent.
void CMyPropertyPage::OnCancel()
{
ASSERT(m_pSheet != NULL);
m_pSheet->EndDialog(IDCANCEL);
}
Now I have a scenario where i have to forcefully close the wizard by sending
SendMessage(WM_COMMAND,IDCANCEL);
Now after the CANCEL message being sent, the PSN_WIZFINISH notification is also sent
In my class, i've overridden the OnWizardFinish to do some functionality.. So when i do a "SendMessage" i dont want the PSN_WIZFINISH to be sent ..
why does it work this way and how do i avoid it ?
Thanx for ur help.
|
|
|
|
|
Hi!
Is there a way to call a managed DLL from an unmanaged MFC class?
MSc Bertil Morefält
|
|
|
|
|
Take a look on the following code:
if ((A) && (B) && (C))
{
...
}
If A evaluates to FALSE Will B or C be evaluated?
Hint: For built-in types A, B and C, the C++ language description by Bjarne Stroustrup defines that B and C will not be evaluated if A is FALSE.
What if A, B, C are macros that expand to complex functions that also do some assignments as side-effects, will this be true also?
What about compilers that do optimizations, or their optimizations have been disabled?
What about plain 'C' code, Do short-cirtuit rule mentioned above is relevant?
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
I believe that the C language specifies that the short-circuit will always take place so that you can DEPEND upon this behavior to avoid problems.
Consider this simple function (which is in our code now...)
BOOL IsEmpty(char* string)<br />
{<br />
if( string && string[0] ){<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}
I am relying upon the short circuit test of string as a pointer to be NON-NULL and the test failing, otherwise I might try to dereference memory I don't own! (Dereferencing a memory address at zero which will lead to the fatal 'access violation' exception on Windows)
|
|
|
|
|
rbid wrote:
If A evaluates to FALSE Will B or C be evaluated?
No. This is ALWAYS the case.
rbid wrote:
What if A, B, C are macros that expand to complex functions that also do some assignments as side-effects, will this be true also?
Yes.
rbid wrote:
What about compilers that do optimizations, or their optimizations have been disabled?
This is nothing to do with optimisations. It's in the standard.
rbid wrote:
What about plain 'C' code, Do short-cirtuit rule mentioned above is relevant?
Yes, it's in the C standard.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Be aware that if you define your own overloaded operators &&, || etc. that they will NOT short-circuit!
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
1. An input array and an output array is passed from Javascript to C++ prgram.
2. C++ program receives the passed javascript arrays as VT_DISPATCH SAFEARRAY's.
3. 'ADO Command' parameters created from the passed input and output arrays and a stored procedure is called.
4. Stored procedure copies input array values to output array.
5. when trying to copy value from the command object back to the output array I am facing problem.
Shown below is the code.
if(varOutParams->vt == VT_DISPATCH)
{
CAuto<safearray*, csadtor=""> ppsaOUT(SafeArrayCreate(VT_VARIANT, 1, 0));
DispToSafeArray(varOutParams->pdispVal, &ppsaOUT);
SafeArrayAccessData(ppsaOUT, (void **)&varArrParams);
int iCounter = 0;
for (prmIterator = vecOutParams.begin(); prmIterator!= vecOutParams.end(); prmIterator++)
{
pPrmObject = *prmIterator;
pPrmObject->get_Value(&varArrParams[iCounter++]);
}
vecOutParams.clear();
SafeArrayUnaccessData(ppsaOUT);
}
|
|
|
|
|
Does somebody know, how to do this?
|
|
|
|
|
Does the PrntScrn key not work, or are you wanting to do it via code?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I have to add an ability to get "screenshots" of fullscreen dos apps to some opensource vnc (UltraVNC, TightVNC or something other...) in order to make possible to programm our samsung office phonestations remotely (7 ones in the different towns). Their program (pcmmc80) is run in fullscreen graphical mode and somewhy doesn't run in VMWare and other VirtualPSs =(
|
|
|
|
|
Hi
Iam calling a fortran function from c++ code.Actually it enters into the fortran code , but it not passes the correct argument values.instaed of passing 1 & 8 valeu it passes the 0 value to the fortran functions.
Please help me to solve this problem.Below is my code.
fortarn function (DLL:Dynamic linked linrary)
SUBROUTINE MATH(INTEGER A, INTEGER B)
!DEC$ ATTRIBUTES DLLEXPORT ::MATH
PRINT*, "Oops!!! I am ForTran manager..."
INTEGER SUM = A+B
PRINT*, "after sum in fortarnlangauge"
PRINT*, SUM
RETURN SUM
END SUBROUTINE MATH
C++ CODE(EXE)
#include <iostream.h>
extern "C" __declspec(dllimport)
int __stdcall MATH(int a , int b );
void main()
{
cout<<"iam checkimg the mixed langauage programming"<
|
|
|
|
|
You need to check if integers in C++ have the same number of bytes than in Fortran. In C++, it depends of the system...
Maybe try this:
extern "C" __declspec(dllimport)<br />
int __stdcall MATH(short a , short b );<br />
and this:
extern "C" __declspec(dllimport)<br />
int __stdcall MATH(long a , long b );
to force the compiler to use 2 bytes (short) or 4 bytes (long).
Hope this helps
|
|
|
|
|
Again I am facing the same problem.
|
|
|
|
|
Hi everyone,
I am quite new here, and actually no so old to C/C++ either.
Has for my problem:
I've been trying to build an OCX wrapper for 3 DLLs. The wrapper itself will also provide a bit of extra functionality of it's own, but
it is basically a wrapper.
So far no big deal. Actually it's even working without any problems. The problem, has I see it, is more of an aestecthics nature than anything else.
You see, although I profit from this by geting to keep and use the DLLs, I'm doing this for a friend and therefore it's suposed to be done a certain way. Which of course is exactly why he askaed for it in the first place, because he doesn't have the time nor the inclination to look into it himself, and also because he has never written a COM or OCX before.
The issue itself has to do with how you access the functionality of each of the DLLs. I am certain everyone here has at least once used the TreeView control. This control has a Nodes colection which can be used to perform certains task on all of the nodes, return a node count, or access an individual node. Now in my case I don't have sutch a collection, what I do have are methods, and some properties that come with the wrapper and one of the reasons for wrappers existance. But I do want them accessed like the Nodes property, meaning I need to implement one Property for each DLL, which will be used to expose that particular DLL functions and properties.
I've build the classes, no problem there. They all have Automation support. Properties and methods are all in place. So far no problem.
Now if this was a COM I wouldn't be asking the next two questions. I know it's probably something I should know, but the truth is I don't.
First : Since I am using Automation on my Wrapper Classes they actually become available for instantiation, which I don't want. So first question is, how do I stop this ?
Second : How do I implement my properties ? In a COM this is kind of easy, just a part of the Dispatch coding. However every attempt of doing it in the sameway has resulted in loss of Wizard assistance (not really a problem), lots of compiler warnings, and a fare number of crashes. So if anyone know how I can implement this I'd apreciate it, preferably with a pointer to some sample code, has I learn a lot faster that way. Just to remove any doubts, what I am trying to do is create 3 properties, one for each DLL, that will then be used to expose the properties and methods provided by that DLL. This would be done in the form:
Wrapper.DLL1.Function1
Wrapper.DLL1.FunctionN
Wrapper.DLL2.Function1
Wrapper.DLL2.FunctionN
Wrapper.DLL3.Function1
Wrapper.DLL3.FunctionN
Sorry, I don't mean to be annoying or anything by explaining it all like this, it's just I am always afraid I somehow mess up and can't get the message through.
I appreciate any help you can provide.
Best regards,
----------------
Lord Phoenix
----------------
|
|
|
|
|
I am developing an MDI application with a Tree View within the MainFrame Window and all MDI Child windows in the right side (within the MainFrame Window).
For each new node added to the tree view , an MDI child window should be created .Thus the GUI represents an Explorer style setup with nodes in the tree view representing the individual child windows..Can anyone help me in this regard.
|
|
|
|
|
How do i get a tooltip displaying the coordinate values of the client view area next to the cursor while moving the mouse?
|
|
|
|
|
Capture mouse when it is in your window.
Process WM_MOUSEMOVE notificaiton messages.
Decode lParam (already in client coordinates)
Update text in ToolTip window
Move your ToolTip window to desired location
Have fun
|
|
|
|
|
Hello,
I tried the below line to make my dialog start at a certain position, with certain size, and prevent the user from moving it afterwards.
SetWindowPos(&this->wndTopMost,StartXPos,StartYPos,DlgWidth,DlgHeight,SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_SHOWWINDOW);
There is no problem with the start position and the size, but I can move it. Also there is some problem with CClientDC::LineTo() function. It sometimes draws after SetWindowPos is called, and sometimes not.
I also want to write a function to enable moving again.
Thanks in advance...
|
|
|
|
|
I'm sure there is an article in the Dialogs section somewhere about this, but off the top of my head...
Handle the WM_NCHITTEST message (OnNcHittest). If you want the normal behaviour, fall through to the standard behaviour.
If you want the dialog locked, return HTCLIENT.
...
ON_WM_NCHITEST()
...
UINT CMyDialog::OnNcHitTest( CPoint point )
{
if (m_bLocked)
return HTCLIENT;
return CWnd::OnNcHitTest (point);
}
Tada!
Iain.
|
|
|
|
|
WM_NCHITTEST did the trick.
thanks a lot!
caykahve
|
|
|
|
|
Override WM_MOVING and WM_SIZING to control how the window can be moved (or resized) by the user.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i am encountering the following problem when making a dll in VC++ which contains functions using apache API.I have added the libraries available with apache installation to the input lib's.it is giving error in linking.
/*******
testfindna.obj : error LNK2001: unresolved external symbol _ap_log_error
testfindna.obj : error LNK2001: unresolved external symbol _ap_rwrite@12
testfindna.obj : error LNK2001: unresolved external symbol _ap_send_http_header@4
testfindna.obj : error LNK2001: unresolved external symbol _ap_set_content_length@8
testfindna.obj : error LNK2001: unresolved external symbol _ap_reset_timeout@4
testfindna.obj : error LNK2001: unresolved external symbol _ap_get_client_block@12
testfindna.obj : error LNK2001: unresolved external symbol _ap_hard_timeout@8
testfindna.obj : error LNK2001: unresolved external symbol _ap_should_client_block@4
testfindna.obj : error LNK2001: unresolved external symbol _ap_setup_client_block@8
Debug/testfindna.dll : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.
*******************/
thanks in advance
pi
|
|
|
|
|
You need to link with the library the contains the mentioned functions (e.g., _ap_log_error ).
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|