|
Hello, first of all excuse my english, as in VC++ I'm just a begginer.
I have a DLL that allows me to interact with a PLC. I need to get some values that are stored in the double format.
the f(x) that allows me to obtain the values from the PLC use a pointer to a void type.
here's a piece of code:
long CAccedirTWinCAT::GetDadesxNom(CString csNom, void *&pParam, int iPort /*=AMSPORT_R0_PLC_RTS1*/)
{
EnterCriticalSection(&m_CritSec);
long lCodiError = 1;
ULONG VarHandle = NULL;
ULONG ulData = NULL;
int iLength = csNom.GetLength();
m_pAddr->port = iPort;
// this is the dll exported function.
lCodiError = AdsSyncReadReq(this->m_pAddr,ADSIGRP_SYM_VALBYHND,m_VarHandle,sizeof(pParam),&ulData);
pParam = (void *)ulData;
LeaveCriticalSection(&m_CritSec);
return lCodiError;
}
and here how I call the f(x).
void *vParam;
m_Accedir.GetDadesxNom(".g_bManual",vParam);
BOOL bEstatManualACT = (BOOL)vParam;
How should I convert the (void *) to a double?
|
|
|
|
|
The function gives a 32-bit value (ULONG cast to a void*), and a double takes 64 bits, so you can't get double values using the function GetDadesxNom(). You might be able to retrieve single-precision floats and convert them to doubles with double dData = reinterpret_cast<float>vParam;
|
|
|
|
|
Hi,
I have problems filling up a structure while debugging.
The Strucutre is something like this:
typedef struct
{
char; // (8Bit)
unsigned int; // (32Bit)
somepointer*; // (32Bit)
}
what makes 9 Byte together.
I want to fill up the struct with a byte-pointer pointing to a stream. That works but the problem is that in debugging mode CHAR seems to be 32Bit long, because when I fill up the struct byte by byte the first byte is placed into the CHAR but it needs 3 more bytes to get to the UNSIGNED INT.
Any ideas ? Thanks!
CU Mario ///
----------------------
www.klangwerker.de
mario@klangwerker.de
----------------------
|
|
|
|
|
The reason is byte packing.
The i386 and later processors can access memory that is aligned or unaligned to specific
boundaries.
For byte size operations, any address is as good as another (not quite true,
but its handled inside the processor).
For word size (16 bit) operations, accesses are faster on 16 bit aligned addresses (every
2 bytes).
For DWORD and pointer size operations, accesses are faster on 32 bit aligned addresses
(every 4 bytes).
Since your structure has a 4 byte sized object (the unsigned int) following the char
it has been aligned to the next optimal address. If you really don't like this you
can instruct the compiler how you want it to behave using the #pragma pack directive.
Stephen Kellett
|
|
|
|
|
I have a very simpl dialog based app that just has a CWebBrowser2 control in it. Every five seconds I call m_WebCtrl.Refresh() .
When running I quite often in the debug window...
First-chance exception in myapp.exe (GDI32.DLL): 0xC0000005: Access Violation.
This does not stop my app, but it just worries me! Any ideas what could be causing this please??
|
|
|
|
|
These are hard to trap, but often harmless.
Sometimes you can get an idea of the general area involved by stopping at a breakpoint (or starting with F10) and modifying the exception behavior so that first chance exceptions cause a break.
After the debug session is started open the Debug menu and select the Exceptions option. In the dialog change the behavior of the access violation from 'Stop if not handled' to 'Stop always'. Then, the next time the OS traps the exception, you'll break into the code - albeit some rather cryptic assembly of GDI32.DLL. If you hit alt+7 to display the call stack, and you're lucky enough to see some files that show you the last made graphics calls, you might be able to infer what's going on.
Very often you won't be able to see much. GDI is the worst, I think, since problems may be bubbling up from some minor driver fluff - who knows? I've seen docs in the MSDN that try to assuage the fears of ardent developers like yourself, and I think the basic dogma these days is to let it be.
The tip here can be useful in other areas though - I can remember using it to straighten out a bad CString initialization once. Always nice to at least try to see what's going on!
|
|
|
|
|
hi,
I have written a MDI program that can create three different views. The problem is that i have no idea on how to maintain each view's title bar's caption. I use back the same doc class for all the view class.
I did something like this:
CDocument * pDoc;
pDodc->SetTitle("HTML View");//for each different view, different caption
When i create a new different view (with other views created earlier), the title bars' caption of all the previously created views follow the caption of the new view. Any idea on how to avoid such situation??
Thanks in advance.
leonwoo
|
|
|
|
|
Overload CMDIChildWnd::OnUpdateFrameTitle() and in that method, set the text to whatever you like.
--Mike--
http://home.inreach.com/mdunn/
The preferred snack of 4 out of 5 Lounge readers.
|
|
|
|
|
Thanks for your answer Micheal.
|
|
|
|
|
in the OnCreate() function of your view's frame window change the lpszWindowName parameter to what you want it to be
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Hi
I need to upload binary file (dll) to SQL Server database throught ADO.
I tried to use "ADODB.Stream" object, but i can't open this stream from the file.
hStream->Open(n, adModeUnknown, adOpenStreamUnspecified, _bstr_t(""), _bstr_t(""));
hStream->LoadFromFile(szFileName);
Could you specify correct syntax for this method call
Thanx.
|
|
|
|
|
Hi
I have one application that generates an Storage of ActiveXControls ( OleDocument -> Save Map-> ...), and I would like to read that storage and just put the ActiveXControls in a normal view, is there any way to do that ?
Thanks, Bye !
Braulio
|
|
|
|
|
HI ALL
I want make simple calculator so I get some problems like :
- try do that :
double d1 = 5/3 ; //same (5/3)
double d2 = 3/2 ;
and you get this result (1)
when you do that in Calculator program(by Microsft)
the result is (1.6666666666666666666666666666667) and (1.5)
the problem here the value after the point didn't appeare
I tried by VISUAL C++6 using (CEDIT box)
- next problem ,when you try to show larg number in (CEDIT box)
the CEDIT box show the number with (e+) like(8.98765431209876e+016)
how I can disable or enable this(e+)
THANK YOU
AHMAD ALWASHALI
|
|
|
|
|
> double d1 = 5/3 ;
The calculation 5/3 is done with integer values, so the result is 1. If you want a double result, convert the operands to double _before_ the calculation:
double d1 = 5.0/3.0;
|
|
|
|
|
Thank you very much
AHMAD ALWASHALI
|
|
|
|
|
HI ALL
pointer of pointer(char** ch)
some times I see this this(char** ch)
for example in (strtod) function
it's strang kind of pointer
can you tell me about this kind of pointer
THANK YOU
AHMAD ALWASHALI
|
|
|
|
|
What more can i say expept
that it's a pointer that points
to a pointer. 8-)
It's used -usually- when you want a function to
return a pointer through it's arguments.
void GetPointer(char** ppChar)
In that case you call the function by passing
the address of the pointer.
char MyChar='A';
char* pMyChar=&MyChar;
GetPointer(&pChar);
- - - - - - - - - - - - - - - - - -
Memory leaks is the price we pay \0
01234567890123456789012345678901234
|
|
|
|
|
Thank you very much
AHMAD ALWASHALI
|
|
|
|
|
HI ALL
My qustion about
bitwise left shift and sight shift Operators << , >>
I don't understand what it does,I searched in MSDN i found
that :
The bitwise shift operators shift their first
operand left (<<) or right (>>) by the number
of positions the second operand specifies.
and then give me this example :
// Example of the bitwise right shift operator
int nNumA=8; // beginning value is 8
nNumA >> 2; // ending value is 2
what this does the (nNumA) stil has the value (8)
Can you tell me what the << , >> do, and when I use it.
THANK YOU
AHMAD ALWASHALI
|
|
|
|
|
Ahmad
the bitwise operators move the bits in a variable left or right the number of positions requested. Take the following code snippet for example.
void main()
{
int nNumber = 8;
nNumber >> 2;
}
If you move the bits set to 1 too far to the left or right they just drop off the end and are lost.
Hope that helps.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
Thank you very much
AHMAD ALWASHALI
|
|
|
|
|
i want to use my program to replace the windows logon dialog box on windows 98/nt/2000,who can tell me what should i do,especally on 98;P
|
|
|
|
|
Hi
I need to call a dos command in my program, which is a win32 console application. Does anyone know how?
Thanks
kk9
|
|
|
|
|
Try system("dir"); or system("command /k dir "); (or cmd for NT). The /k switch leaves the user at the command prompt until they type exit to return to your prog, so this acts as a sort of 'shell to DOS' command.
|
|
|
|
|
If I understand you correctly you wish to call a DOS command from your program without suspending the running of it or forcing a Command Prompt to appear for the running of any commands. If this is correct, you need to call the system function.
int system( const char *command );
Only problem with this is the fact it can only return an int to tell you if it worked or not and also any error that occurred via errno. If you wish to get access to the response of the DOS command you would I suppose have to pipe the DOS command to a file ie. [nRetVal = system("dir C:\Program Files > C:\Output1.txt")] and then parse the results from the file later in your program.
Hope this helps.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|