|
say what?!?! can you try and explain your problem a little bit. What do you mean by the other side is unknown? And, which part of sending over TCP/IP don't you understand?
Please, be a little more specific about what you are trying to accomplish. It will help us give you the right answer.
----
www.digitalGetto.com
|
|
|
|
|
U right
What I need to do is this:
Take a structure and send over a TCP/IP to a client/server on the other side.
The problem:
I need to transform the structure to an array of bytes which I don’t know how.
I can't do this with the serialize function since the other side may or may not have the unserialize function.
I tried to do this with casting but it didn’t work.
I tried to do this with union' but u can't make an array inside a structure.
I tried to do it whit unmanaged code, but the Socket class will accept only managed Byte array.
There, I told u all I know. Can u help me?
|
|
|
|
|
|
The structure that you are trying to send.. is that something you made?
Is the receiving end a program that you're writing? If not, what format does it expect the data to be in?
Serialization/Deserialization is a process. That's all. There is nothing magic involved. You can always write your own functions to serialize and deserialize data. Here's an example of a simple structure that is serialized into a byte array:
struct myStruct
{
int iValue;
string strValue;
public myStruct(byte[] sourceArray)
{
int k;
if(sourceArray.Length > 2)
{
this.iValue = sourceArray[0] + sourceArray[1] * 256;
this.strValue = "";
k = 2;
while(sourceArray[k]!=0 && k<sourceArray.Length)
this.strValue += (char)sourceArray[k++];
}
}
public byte[] Serialize()
{
int k;
byte[] tmpArray = new byte[2 + this.strValue.Length];
tmpArray[0] = this.iValue & 0xFF;
tmpArray[1] = (this.iValue >> 8) & 0xFF;
k = 0;
while(k < this.strValue.Length)
tmpArray[k + 2] = this.strValue.ToCharArray()[k++];
return tmpArray;
}
}
byte[] t;
myStruct A;
myStruct B;
A = new myStruct();
A.iValue = 567;
A.strValue = "test string";
t = A.Serialize();
B = new myStruct(t);
obviously, once you serialize your structure into an array you can send it over TCP/IP using a WinSock
----
www.digitalGetto.com
|
|
|
|
|
First of all, thank u all!!!
Let me tell u the all story.
What I need to do is to send a message over the net.
So, I have this structure (which is the message to be sent), and then I have to send it (somehow…)
Then, I receive a message which I have to decode and then, according to the header, I parse it back to a structure which I will use in the program.
I know that for some of u readers it may seem like a dumb question, but since it is my first time that I have to deal with communication, please accept my ignorance.
Much appreciated
|
|
|
|
|
What is your question exactly, how to send/receive data via TCP/IP, or how to encode/decode your data?
If it is the former, start from here.
Best,
Jun
|
|
|
|
|
If u put it this way, then, it is how to encode and decode the data.
But remembering that I can’t use the serialization option that .net gives me.
Meaning, converting a structure to a Byte array and the other way around.
|
|
|
|
|
Hi
Actually I am facing the problem that I am not being able to use the templates in managed c++.net code.But the unmanaged code uses the templates.Is there a way out in the dot net to use the templates in managed c++ code.
There is also one more problem that in my unmanaged c++code i have been using the multiple inheritance and multiple inheritance is not supported in managed c++ .net.And If I use the interfaces then the interfaces don't contain data.Is there a way out.
Thanks.
hy
|
|
|
|
|
All
I have a need to automate a portion of a web page login. I have developed a small API based on WEBBrowser2 and CSharp. I can send click events or fill in edit boxes etc with items that are available within the HTML page being viewed. There is an issues however, when Frames are introduced. If an HTML page has a Frame in it, I cannot call the Navigate method successfully withing WebBrowser2 because it thinks it is on the root page not the Frame. Is there a way to itterate through the available frames on a page and call events on particular Frames. For example if there was a button in a Frame, how would one Navigate to that frame and activate that button?
Thanks for your help
Dave
|
|
|
|
|
I'm trying to code a function that checks whether a number is a prime number.
When trying to implement a known algorithm...I'm getting unexpected results.
I know it's not managed c++, but I would appreciate help. Any ideas pls?
#pragma once
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
bool isPrime (int Number)
{
/* hard-setting prime numbers */
if (Number <= 1) return false;
/* Algorithm: Sieve of Erastosthenes*/
int *mPrimeNumber;
mPrimeNumber = new int[Number + 1];
int iIndex;
/* initialize values */
for (iIndex = 0; iIndex <= Number; iIndex++)
{mPrimeNumber[iIndex] = 0;}
iIndex = 2;
mPrimeNumber[iIndex] = 1;
for (iIndex = iIndex * iIndex; iIndex <= Number; iIndex += 2)
{mPrimeNumber[iIndex] = 2;}
iIndex = 2;
while (iIndex <=Number)
{ iIndex++;
if (mPrimeNumber[iIndex]==2)
{mPrimeNumber[iIndex] = 1;
for (int iInnerIndex = iIndex; iInnerIndex <= Number; iInnerIndex += iIndex)
{mPrimeNumber[iIndex]= 2;}
}
}
// set return value
switch (mPrimeNumber[Number])
{ case 1:
return true;
break;
case 2:
return false;
break;
case 0:
cout << "Error!: " << Number << " not checked!!" << endl;
break;
default:
cout << "Error!: Invalid return value"<< endl;
}
delete [] mPrimeNumber;
};
void main ()
{
int iNumber = 0;
while(iNumber != 9999)
{
cout << "Enter an integer:" << endl;
cin >> iNumber;
// test isPrime function
if (isPrime(iNumber) !=0)
{cout << "Prime" << endl;}
else
{cout << "Not-Prime" << endl;}
}
}
Jon
|
|
|
|
|
I have an NT Service program written with VC++ 6.0 as ATL/COM components that runs on W2K or XP. Now I want to upgrade to VC++ 2005 but not sure where to start. It has nothing at all to do with the web, just processes database requests from clients on wireless scanning devices. The wireless device needs some data from a database, calls my service which processes the request, formats the data for the device then returns the formatted data all through various COM calls.
I guess my question is: is there any advantage to migrating to VC++ 2005 other than getting a new compiler? Are there any books you would recomment that might help me migrate the program to managed c++?
Thanks for any inputs.
|
|
|
|
|
You can still compile it as native code, VC8 doesn't force you to convert it all to managed.
|
|
|
|
|
Is there anyone who would be so kind to tell me where can I get some sorce code about a software which can read or edit the powerpoint file? Many thanks!
thinkpader
|
|
|
|
|
Hi !
I would like to ask your help in a problem I got stuck completely for weeks now.
I need to check and clear the Enhance pointer precision checkbox whitin Mouse settings under Control Panel of XP.
Could somebody help me please ?
Many thanks in advance,
Moore
|
|
|
|
|
Programatically?
Best,
Jun
|
|
|
|
|
Of course programtically, yes. Manually with mouse it is easy, but I would need to do it from source code from an application.
Any idea how ?
Many thanks,
Moore
-- modified at 17:52 Friday 30th June, 2006
|
|
|
|
|
hi, i am tyring to use OpenCV code in VS .net 2003 Visual C++ Windows forms.
when i build, it give me no error but when it start it give an error :
An unhandled exception of type 'System.TypeLoadException' occurred in cam1.exe
Additional information: Could not load type CvCapture from assembly cam1, Version=1.0.2371.20291, Culture=neutral, PublicKeyToken=null.
The error seen to be from this line:
capture = cvCaptureFromCAM(0);
new to programming
-- modified at 3:01 Thursday 29th June, 2006
|
|
|
|
|
|
Hey eveybody,
I have written a WndProc() function that detects the insert and removal of a USB drive and
want to pull out the specific LParam values to get the name of the drive and other info.
The examples I've found so far use a particular C# code that goes like this...
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct DEV_BROADCAST_VOLUME<br />
{<br />
public int dbcv_size;<br />
public int dbcv_devicetype;<br />
public int dbcv_reserved;<br />
public int dbcv_unitmask;<br />
}<br />
protected override void WndProc(ref Message m)<br />
{<br />
const int WM_DEVICECHANGE = 0x0219;<br />
const int DBT_DEVICEARRIVAL = 0x8000;
const int DBT_DEVTYP_VOLUME = 0x00000002;
if (m.Msg == WM_DEVICECHANGE && m.WParam.ToInt32() == DBT_DEVICEARRIVAL)<br />
{<br />
int devType = Marshal.ReadInt32(m.LParam,4);<br />
if(devType == DBT_DEVTYP_VOLUME)<br />
{<br />
DEV_BROADCAST_VOLUME vol;<br />
vol = (DEV_BROADCAST_VOLUME) Marshal.PtrToStructure(m.LParam,typeof(DEV_BROADCAST_VOLUME));<br />
MessageBox.Show(vol.dbcv_unitmask.ToString("x"));<br />
}<br />
}<br />
base.WndProc (ref m);<br />
}<br />
And I've been trying to get the LParam into my structure like this:
<br />
__gc struct Volume<br />
{<br />
int size;<br />
int devicetype;<br />
int reserved;<br />
int unitmask;<br />
}<br />
<br />
protected: void WndProc(System::Windows::Forms::Message* message) <br />
{<br />
...<br />
if(message->Msg == WM_DEVICECHANGE)<br />
{<br />
if(message->WParam == DBT_DEVICEARRIVAL)<br />
{<br />
lVolume = (Volume*)Marshal::PtrToStructure(message->LParam,__typeof(Volume));<br />
<br />
String* str = MaskToLogicalPaths(lVolume->Mask);<br />
this->m_FoundBox->Text = String::Format("Plugged In: {0}",str);<br />
}<br />
else <br />
if(message->WParam == DBT_DEVICEREMOVECOMPLETE)<br />
{<br />
this->m_FoundBox->Text = String::Format("UnPlugged: {0}",message->WParam.ToString());<br />
} <br />
}<br />
}<br />
This continues to not work in MC++.
For some reason I cannot find a viable alternative to the C# code in MC++. My errors include
the dreaded run-time:
"The specified structure must be blittable or have layout information..."
among other more standard compile errors for instantiating the structure incorrectly.
I know theres a way to do this but havent found it yet.
Any help you all could be would be greatly appreciated!
ScottLeff
sleff@yahoo.com
|
|
|
|
|
How to apply "Force file output" option in Visual Studio.NET i.e. VC7. In Visual Studio 6.0, it is available in "Link-->Customize" option in Project Settings of VC++ project.
Can any one help me out please
|
|
|
|
|
Hi All,
In C++/CLI I have used a 2 Dimensional String Array.
My code:
array<String^,2> ^strarr=gcnew array<String^,2>(2,2){"focus1","focus2","focus3","focus4",};
and when I want a string to print on console
ie
Console::Writeline("{0}",strarr[0][0]);
compiler is giving Error.
can any one suggest
Bye..
G.Nagaraju
|
|
|
|
|
Hi,
if want to directly initialize your array then you'll have to do it like this:
<code>
array<String^,2>^ strarr = gcnew array<String^,2>{{"focus1","focus2"},{"focus3","focus4"}};
Console::WriteLine("{0}",strarr[0,0]);</code> In additon I would recommend you to read this article.
http://www.codeproject.com/managedcpp/cppcliarrays.asp[^]
best regards Tobias
|
|
|
|
|
hi.I am using visual studio .net 2003 and I am new to managed c++.
I have to write joystick controller(mouse stick)but I dont now where to start.
|
|
|
|
|
What do you mean by a joystick controller? To me the hardware is the controller and the software is the driver and your program communicates with this driver by an api.
I assume you need to have your program use the joystick support that is built in the operating system? DirectInput (part of directx) has support for joysticks.
John
|
|
|
|
|
I have to create a GUI which control the camera.in my GUI i need to create a mouse stick which controls the camera like rotate left or right. but i get stuck on the mouse stick.In order to create this mouse stick where should i start.
|
|
|
|