|
Should be:
void func1(char chx[], int y)
{
int wsn = 0;
wsn = *(int *)chx;
if (wsn == 0) {
...
}
}
The variable name chx is already a pointer to the array, adding the addressof operator creates a pointer to that pointer.
|
|
|
|
|
Thanks, but I tested, &chx = chx.
|
|
|
|
|
No it doesn't. I have no idea how you tested this but it is not correct. Build the following, step through it with your debugger and you will see that they are different.
int* pAddressOf = (int *) (&chx);
int* pNormal = (int *)(chx);
|
|
|
|
|
I tested in Visual studio IDE.
char s1[] = {'H', 'e', 'l', 'l', 'o'};
printf("%lX,%lX",s1,&s1);
And I get same value for s1 and &s1.
|
|
|
|
|
And I tested your code in Visual studio, use Printf("%lX"),
It shows same value too
|
|
|
|
|
That may be true, but sending those values to printf is not the same as casting to pointers. You can confirm it by printing out the values of the two pointers created in my two lines of code.
|
|
|
|
|
|
Windows 7, Visual Studio 2008, C++
I am writing a TCP/IP utility that can be run/used by a non-windowing application. An MFC dialog stands in for the main app during development. The utility runs as a separate thread and communicates with the main app via events and a shared memory structure. Keeping this short:
Is there a mechanism that the TCP utility can use to trigger a method in the MFC?
Details
Presume the dialog has: OnBnClickedShowStatus(…) When the button is clicked this method reads some variables from the shared structure and displays them in the dialog. Can that button, or its essential code, be triggered by an event from the TCP utility?
The alternative is to create a timer and have it run every 300 milliseconds or so. I am hoping for something that is as simple as the timer and causes minimal additional coding in the TCP utility.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
A better solution would be to implement the TCP utility as a library that can be called from any other application: windows, non-windows, MFC or not. It could incorporate a call back feature that would allow it to call into the controlling app whenever necessary.
|
|
|
|
|
I don't have any idea of how to do that, but it sounds like a good concept. I did some searching and will look into that.
Still, finding this particular concept of having the thread call into the controlling app may be a bit difficult to discover. Can you give me a few words or a link that discusses that in particular?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 7-Sep-14 11:15am.
|
|
|
|
|
Export an API from the library that takes a function pointer as an argument. Then use this API from the main program to pass a function pointer into the library so it can call back to the main program.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am having a bit of trouble with that concept. I am currently writing and testing this utility, a TCP/IP class that is run under a thread separate from the main app. The main app instantiates a class call C_Log_Writer to write data to a log file. Main handed a pointer to C_Log_Writer to the thread and it tried to write some data to the log. That crashed the app repeatedly. The prompted the conclusion that since they are in separate threads each with its own execution pointer, that was not a good idea.
Creating a new instance of C_Log_Writer for the thread resolved the problem. There are two log files, but that's okay. That makes me concerned that calling a function across a thread boundary might be a problem.
That said:
When you write: Export an API from the library, I take that to mean export a function from the TCP utility. Do I follow you correctly?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
1. Yes, export a function from the utility
2. About the crashing when passing a pointer to your log class: Where did it crash? Can you pinpoint that? It might have something to do with the TCP utility using a different heap from the main exe.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
please help me coding (in language C)quine mcCluskey's method for solving upto 8,9 or 10 variables whose minterms are to be generated automatically, only the no. of minterms, no.of variables and vectors of minterms are user given
|
|
|
|
|
And please do not repost the same question.
|
|
|
|
|
can someone plez help me coding the program in C for implementing Quine McCluskey's method for 8,9 or 10 variables where the inputs are to be generated automatically. Only the no. of variables, no. of minterms and a vector of minterms are user given.
|
|
|
|
|
|
Windows 7, Visual Studio 2010, C++
structure m_common_data contains:
struct st_common_data
{...
LPWSABUF p_lpwsabuf_array[ TCP_SERVER_PACKET_BUFFER_SIZE ];
where the constant has the value 16.
The main app dot H contains:
char m_send_buf_array[ TCP_SERVER_PACKET_BUFFER_SIZE ][TEST_BUFFER_SIZE];
where TEST_BUFFER_SIZE is an arbitrary 1024 for initial testing.
the main app dot CPP initializes all with this, and after some debugging variables were installed looks like this:
void CTest_ServerDlg::Initialize_Send_Buffers()
{
unsigned int db1, db2a, db2b, db2c, db2d, db3, db4, db5, db6, db7;
for( int i = 0; i < TCP_SERVER_PACKET_BUFFER_SIZE; i ++ )
{
for( int j = 0; j < TEST_BUFFER_SIZE; j ++ )
{
m_send_buf_array[ i ][ j ] = ( ( i * 5 ) + j ) % 255;
}
db1 = (unsigned int) &m_send_buf_array[ i ][0];
db2a = m_send_buf_array[ i ][0];
db2b = m_send_buf_array[ i ][1];
db2c = m_send_buf_array[ i ][2];
db2d = m_send_buf_array[ i ][3];
db3 = sizeof( m_send_buf_array[ i ] );
db4 = (unsigned int) &m_common_data;
db5 = (unsigned int) &( m_common_data.p_lpwsabuf_array[ i ] );
db6 = (unsigned int) &( m_common_data.p_lpwsabuf_array[ i ]->buf );
m_common_data.p_lpwsabuf_array[ i ]->buf = &m_send_buf_array[ i ][0];
m_common_data.p_lpwsabuf_array[ i ]->len = sizeof( m_send_buf_array[ i ] );
}
When stopped on the first time through the i loop, i = 0.
The debugger shows
db1 = a valid looking address
dba,b,c, and d contain: 0, 1, 2, 3, as expected
db3 = 0X400, expected
db4 looks like a valid address
db5 = db4 + 0xF0 again expected because of items not shown.
db6 shows the value 4.
db6 is the value I do not comprehend. I expected a valid address here, specifically I expected the value to be 4 larger than db5 because the ->buf item of structure WSABUF is the second item in the structure.
Please explain why db6 has the value 4 rather than the address of item ->buf.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 14-Aug-14 11:56am.
|
|
|
|
|
Your declaration
LPWSABUF p_lpwsabuf_array[ TCP_SERVER_PACKET_BUFFER_SIZE ];
says that p_lpwsabuf_array is an array of LPWSABUF items, that is pointers to WSABUF structures. Are you sure that this is what youe meant, rather than an array of actual structures?
|
|
|
|
|
The Microsoft web pages here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms741542(v=vs.85).aspx[^] has:
typedef struct __WSABUF {
u_long len;
char FAR *buf;
} WSABUF
Edit this line:
m_common_data.p_lpwsabuf_array[ i ]->buf ( <- delete ">buf" and retype the > ) = &m_send_buf_array[ i ][0];
If is delete the end of the assignment and retype in the ->, intellisense says the options are len and buf. Going on that I think the declaration and statement are correct. Are they incorrect?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
I'm not sure what you are saying here, but my previous question still stands. Is p_lpwsabuf_array supposed to be an array of WSABUF structures, or an array of pointers? There is a big difference.
|
|
|
|
|
I am expecting an array of structures. The MS page shows this:
typedef struct __WSABUF { u_long len; char FAR *buf; } WSABUF, *LPWSABUF;
I am uncertain as to how the phrase ..;., *LPWSABUF; is read.
The line of code in question is an assignment to:
m_common_data.p_lpwsabuf_array[ i ]->buf
When I get here:
m_common_data.p_lpwsabuf_array[ i ]
and type in the two characters ->
Intellisense prompts me for the fields len and buf. I interpert that as saying Intellisens interperts the declaration as an array of structure, each of which has a pointer to the data to be sent.
But when I try to show the address of the buf pointer, (not the value of the pointer, but the address of where the pointer is held in the structure), the debugger provides an address of 4. Since that is a contradition, there is something I am misinterperting.
Edit: I should change the name from p_lpwsabuf_array to lpwsabuf_array as the intent is an array of structure. The p_ prefix is misleading.
EDIT: She key here seems to be that I don't know how to read the declaration of WSABUF, *LPWSABUF. I tried using an array of WSABUF but WSASend demands LPWSABUF. When I use that in the declaration I am unable to assign an address to the ->buf pointer. If the original declaration is WSABUF, how is that cast to LPWSABUF so WSASend will accept it? If the other way around, how is the code to be changed to assign an address to ->buf in the code I posted?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 12-Aug-14 19:33pm.
|
|
|
|
|
typedef struct __WSABUF { u_long len; char FAR *buf; } WSABUF, *LPWSABUF;
You read the above as struct __WSABUF declares a structure whose contents are declared within the braces following. The typedef specifier creates synonyms for the following declaration, which in their turn can be modified types. In this case WSABUF is a synonym for the preceding structure declaration. *LPWSABUF is a synonym for a pointer to the structure: the preceding asterisk tells us that it is a pointer.
So the declaration
LPWSABUF p_lpwsabuf_array[ TCP_SERVER_PACKET_BUFFER_SIZE ];
declares an array of pointers. However according to the documentation for WSASend [^], the second parameter is a pointer to an array of WSABUF structures, not pointers, so it should be declared, and initialised something like:
WSABUF wsabuf_array[ TCP_SERVER_PACKET_BUFFER_SIZE ];
for (int i = 0; i < TCP_SERVER_PACKET_BUFFER_SIZE; ++i)
{
wsabuf_array[i].len = 16; wsabuf_array[i].buf = new char[16]; }
Then when you need to use a pointer to the array on a call to WSASEND you just use the array name, which the compiler converts to a pointer to the first element thus:
int result = WSASend(socket, wsabuf_array, count, ... etc)
Does that make sense?
|
|
|
|
|
Good Morning To You,
It is 5:50 AM here and I wanted to check for replies but am not yet awake enough to write code. It sort of makes sense. It makes enough sense for me to create a new solution and try some examples with your comments to see how they work out. I'll do that before getting back to my main project.
I really appreciate you taking the time to explain this.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Supplementary point. Since p_lpwsabuf_array is declared as an array of pointers, each element needs to be initialised with the address of a real WSABUF .
|
|
|
|