|
Ok, it is true it is the real hell........
I think I'm going to wait for a new redistributable package of .NET 2005.....
Thanks
|
|
|
|
|
Can I send text from a BackgroundWorker::DoWork() to a listbox in the main thread ? I want to keep the listbox in the main thread up to date with what's going on in BackgroundWorker::DoWork(). The BackgroundWorker::ProgressChanged() hasn't the parameter I need ( String^ ) and if I send the text straight to the listbox, an exception is raised. If not, is there another way to do it ?
|
|
|
|
|
As a general rule you can only touch GUI objects from the thread that created them. Use BeginInvoke() method on the form to transfer the call to the GUI thread and update the listbox from there. Once in the GUI thread check for IsDisposed before updating the listbox as its possible for the form to be destroyed beteen you calling BeginInvoke and the actual function being called by the GUI thread
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
A garbage value is the answer but the code seems to be perfectly alright.
# include <iostream.h>
# include <conio.h>
void input_one(char *);
void main()
{
clrscr();
char string[20];
input_one(string);
cout<<"\n\n\n the string given is -> "<<string;
}
void="" input_one(char="" *solo)
{
="" char="" temp[20];
="" cout<<"\n="" \n="" enter="" the="" string="" -=""> ";
cin>>temp;
solo=temp;
}
|
|
|
|
|
You get garbage because instead of copying char temp[20] content to the char string[20], you set adress for char *solo to the first temp's array element.
Doing this: solo=temp; is exacly the same as: solo=&temp[0];
Remember: Array's name is always it's beginning adress.
And you should ask about it on Visual c++ forum.
|
|
|
|
|
Modify this to,
void input_one(char *);
void main()
{
clrscr();
char string[20] = {0};
input_one(string);
cout<<"\n\n\n the string given is -> "<<string;
}
void input_one(char *solo)
{
char temp[20] = {0};
cout<<"\n \n Enter the string -> ";
cin>>temp;
strcpy_s(solo,20,temp);
}
p.s. Use VC++ forum for such question , not involving CLI is any form.
-- modified at 23:04 Sunday 4th March, 2007
Other way is ,
void input_one(char *);
void main()
{
clrscr();
char string[20];
input_one(string);
cout<<"\n\n\n the string given is -> "<<string;
}
void input_one(char *solo)
{
cout<<"\n \n Enter the string -> ";
cin>>solo;
} -- modified at 23:07 Sunday 4th March, 2007
|
|
|
|
|
Zealous_Me wrote: What is wrong with this ? ? ?
maybe the abusive way you ask things...
do you realloy need to ask all in bold ??
are you sure your code deserves the C++/CLI forum ? for me, it leads to the Visual C++ only
|
|
|
|
|
Whats the easiest way to convert from System::String to std::string?
With value types it easy.
double a = 0.1;
System::Double b = a
double c = *reinterpret_cast<double^>(b);
For the time being I've just been using CStrings.....
System::String^ managed_string = "Hello World";
CString str = managed_string;
std::string std_string = str;
Not exactly slick though!!!
Just trying to get an idea of what it the most efficient way, and then I'll probably just create a macro for it.
|
|
|
|
|
<br />
#include < string ><br />
<br />
string os;<br />
String ^s;<br />
<br />
using namespace Runtime::InteropServices;<br />
const char* chars = <br />
(const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();<br />
os = chars;<br />
Marshal::FreeHGlobal(IntPtr((void*)chars));
|
|
|
|
|
Thanks. Had just got it working along the same lines.
|
|
|
|
|
In a TCPListener program I've coded, I used the sample codes about TCPListener I found in MSDN Library. But, when I execute this program, the interface doesn't give any response to other events such as clicking buttons, since the continuous loop prevents the other codes to be run. I know that I must do multithreading, but I don't know how to do. . Meanwhile, I also tried to use "BackgroundWorker" component, but it caused the data transfer to fail. Here's sample code, what can I do?
private:
void ServerActivate()
{
try
{
Int32 port = 10000;
IPAddress^ localAddr = IPAddress::Parse(myipBox->Text);
TcpListener^ server = gcnew TcpListener(localAddr,port);
server->Start();
array<byte>^bytes = gcnew array<byte>(256);
String^ data = nullptr;
// Enter the listening loop.
while (true)
{
MessageBox::Show("Ready To Receive!");
TcpClient^ client = server->AcceptTcpClient();
NetworkStream^ stream = client->GetStream();
Int32 i;
while ( i = stream->Read( bytes, 0, bytes->Length ) )
{
data = System::Text::Encoding::ASCII->GetString( bytes, 0, i );
outputBox->Items->Add(data);
data = data->ToUpper();
array<byte>^msg = System::Text::Encoding::ASCII->GetBytes(data);
stream->Write( msg, 0, msg->Length );
}
client->Close();
}
}
catch (SocketException^ e)
{
MessageBox::Show("Socket Exception Occured!");
ShowLoginBox();
}
}
|
|
|
|
|
Nonreturn wrote: what can I do?
I suggest you find a multi-threading tutorial and deal with learning about multi-threading without any socket aspects. Once you understand what is involved in working with mulitple threads then dealing with the socket aspects should be easier.
led mike
|
|
|
|
|
Is there any tutorial u suggest ?
|
|
|
|
|
I own / read the First Edition and strongly recommend it.
Advanced Windows[^]
led mike
|
|
|
|
|
Dear all,
there are something wrong in the last message, the exactly source code is as below:
// 3964PROTOCOL.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <conio.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <dos.h>
#include <bios.h>
#include "perce.h"
#define ESC 27
void interrupt(*oldvect_ser)();
extern void interrupt int_sio();
extern void restore_8250 (void);
extern void init_8250 (void);
extern void send_tele (char *, short);
extern WORD state, receive_counter, protocol_error;
extern BYTE receive_buffer[];
BYTE choice,sio_eoi;
BOOL receive, autosend;
WORD Com_basis,len;
BYTE send_buffer[BUFFER_MAX];
BYTE tmp_buffer[BUFFER_MAX];
BYTE *mode,*port;
/*=========================================================*/
void warte (void)
{
long i;
/* warte ein wenig */
for (i=0;i<500000;i++) i = i;
}
/*-----------------------------------------------------------------------
* MENUE
*-----------------------------------------------------------------------*/
void menue (void)
{
clrscr();
printf ("\n\n");
printf ("Final Version of KUKAVISION.EXE \n");
printf ("Serial device with 3964R protocol mod. P.S. 08.08.03\n\n");
printf ("[1] send teststring [4] COM 1 \n");
printf ("[2] getNum [5] COM 2 \n");
printf ("[3] getDat [6] reset protocol\n");
printf (" [ESC] quit\n");
printf ("Aktueller Port: %s\n",port);
printf ("Mode : %s\n", mode);
printf ("Number of elements: %d\n",numEl);
printf ("Element index: %d\n",elementIndex);
printf ("Element Data: %s\n---------\n", &send_buffer[0]);
}
/******************************
SEND_TELEGRAM
*******************************/
void send_telegram (BYTE *buffer)
{
if ((len = strlen (buffer)) > 0)
{
send_tele (buffer, len);
warte ();
warte ();
warte ();
if (state == E1)
{
state = RUHE;
protocol_error=2;
}
else protocol_error=6;
}
/*********************
MONITORING
**********************/
void monitoring (void)
{
short i;
printf("-> : ");
for (i=0;i<receive_counter;i++)
{
="" if(isprint(receive_buffer[i]))="" printf("%c",="" receive_buffer[i]);
="" else="" printf("0x%x",="" }=""
="" printf("\n");
="" receive="FALSE;
" }
="" *--------------------------------------------------------------------------
="" *="" function:="" main
="" hauptprogramm
="" *--------------------------------------------------------------------------*="" void="" main="" ()
="" int="" sio_int_nr,i;
="" j;="" sake="" char="" *fields;
="" bool="" quit="FALSE;
" com_basis="0x3F8" ;="" *standard-port="" com1="" sio_int_nr="0xC;" *irq*="" sio_eoi="0x
" port="COM 2" ;
="" oldvect_ser="getvect(sio_int_nr);
" setvect(sio_int_nr,int_sio);
="" state="RUHE;
" choice="protocol_error" =="" 0;
="" false;
="" mode="ready" elementindex="0;
" init_8250="" ();
="" menue="" do
="" if="" (bioskey(1))
="" switch="" (choice)
="" case="" esc:="" ganz="" raus="" break;
="" '1':="" send="" send_telegram="" (&send_buffer[0]);
="" '2':="" getnum="" strcpy(&receive_buffer[0],"getnum");
="" '3':="" getdat="" strcpy(&receive_buffer[0],"getdat");
="" '4':="" irq="" 4="" '5':="" com2="" '6':="" reset="" default:;
="" (receive)
="" monitoring="" ();="" (strcmp("getnum",&receive_buffer[0])="=" 0)="" printf("getnum="" erhalten\n");
="" if(="" imaqreadfile()="=" -1)
="" printf("fehler="" beim="" lesen="" der="" datei\n");
="" numel="imaqGetNbElements();" menue();
="" (strcmp("getdat",&receive_buffer[0])="=" if(elementindex=""> numEl){
printf("Keine Daten mehr vorhanden\n");
for (i=0;i<buffer_max;i++)
sprintf(&send_buffer[i],"\0");=""
="" imaqclose();
="" }
="" else="" {
="" dataerr="imaqGetData(elementIndex," send_buffer);
="" if="" (dataerr="=0)
" send_telegram="" (&send_buffer[0]);="" menue();
="" elementindex++;
="" (protocol_error)
="" switch="" case="" 1:
="" printf("\ncrc-error="" (nak-="">) !!\n");
break;
case 2:
printf("\nno response (DLE) !!\n");
break;
case 3:
printf("\nno send quitt (DLE) !!\n");
break;
case 4:
printf("\nReceive buffer overflow !!\n");
break;
case 5:
printf("\nrepeating telegram (->NAK) !!\n");
break;
case 6:
printf("\nno teststring defined\n");
break;
case 7:
printf("\nSTX\n");
break;
default:;
}
protocol_error = 0;
}
} while (!quit);
restore_8250 ();
setvect(sio_int_nr,oldvect_ser);
}
|
|
|
|
|
|
Dear all,
Now I have a problem with a small program Win32 console application for communication via RS232 with 3964 protocol, so anybody please help me compile this source code or show me what is wrong:
// 3964PROTOCOL.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <conio.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <dos.h>
#include <bios.h>
#include "perce.h"
#define ESC 27
void interrupt(*oldvect_ser)();
extern void interrupt int_sio();
extern void restore_8250 (void);
extern void init_8250 (void);
extern void send_tele (char *, short);
extern WORD state, receive_counter, protocol_error;
extern BYTE receive_buffer[];
BYTE choice,sio_eoi;
BOOL receive, autosend;
WORD Com_basis,len;
BYTE send_buffer[BUFFER_MAX];
BYTE tmp_buffer[BUFFER_MAX];
BYTE *mode,*port;
/*=========================================================*/
void warte (void)
{
long i;
/* warte ein wenig */
for (i=0;i<500000;i++) i = i;
}
/*-----------------------------------------------------------------------
* MENUE
*-----------------------------------------------------------------------*/
void menue (void)
{
clrscr();
printf ("\n\n");
printf ("Final Version of KUKAVISION.EXE \n");
printf ("Serial device with 3964R protocol mod. P.S. 08.08.03\n\n");
printf ("[1] send teststring [4] COM 1 \n");
printf ("[2] getNum [5] COM 2 \n");
printf ("[3] getDat [6] reset protocol\n");
printf (" [ESC] quit\n");
printf ("Aktueller Port: %s\n",port);
printf ("Mode : %s\n", mode);
printf ("Number of elements: %d\n",numEl);
printf ("Element index: %d\n",elementIndex);
printf ("Element Data: %s\n---------\n", &send_buffer[0]);
}
/******************************
SEND_TELEGRAM
*******************************/
void send_telegram (BYTE *buffer)
{
if ((len = strlen (buffer)) > 0)
{
send_tele (buffer, len);
warte ();
warte ();
warte ();
if (state == E1)
{
state = RUHE;
protocol_error=2;
}
else protocol_error=6;
}
/*********************
MONITORING
**********************/
void monitoring (void)
{
short i;
printf("-> : ");
for (i=0;i<receive_counter;i++)
{
="" if(isprint(receive_buffer[i]))="" printf("%c",="" receive_buffer[i]);
="" else="" printf("0x%x",="" }=""
="" printf("\n");
="" receive="FALSE;
" }
="" *--------------------------------------------------------------------------
="" *="" function:="" main
="" hauptprogramm
="" *--------------------------------------------------------------------------*="" void="" main="" ()
="" int="" sio_int_nr,i;
="" j;="" sake="" char="" *fields;
="" bool="" quit="FALSE;
" com_basis="0x3F8" ;="" *standard-port="" com1="" sio_int_nr="0xC;" *irq*="" sio_eoi="0x
" port="COM 2" ;
="" oldvect_ser="getvect(sio_int_nr);
" setvect(sio_int_nr,int_sio);
="" state="RUHE;
" choice="protocol_error" =="" 0;
="" false;
="" mode="ready" elementindex="0;
" init_8250="" ();
="" menue="" do
="" if="" (bioskey(1))
="" switch="" (choice)
="" case="" esc:="" ganz="" raus="" break;
="" '1':="" send="" send_telegram="" (&send_buffer[0]);
="" '2':="" getnum="" strcpy(&receive_buffer[0],"getnum");
="" '3':="" getdat="" strcpy(&receive_buffer[0],"getdat");
="" '4':="" irq="" 4="" '5':="" com2="" '6':="" reset="" default:;
="" (receive)
="" monitoring="" ();="" (strcmp("getnum",&receive_buffer[0])="=" 0)="" printf("getnum="" erhalten\n");
="" if(="" imaqreadfile()="=" -1)
="" printf("fehler="" beim="" lesen="" der="" datei\n");
="" numel="imaqGetNbElements();" menue();
="" (strcmp("getdat",&receive_buffer[0])="=" if(elementindex=""> numEl){
printf("Keine Daten mehr vorhanden\n");
for (i=0;i<buffer_max;i++)
sprintf(&send_buffer[i],"\0");=""
="" imaqclose();
="" }
="" else="" {
="" dataerr="imaqGetData(elementIndex," send_buffer);
="" if="" (dataerr="=0)
" send_telegram="" (&send_buffer[0]);="" menue();
="" elementindex++;
="" (protocol_error)
="" switch="" case="" 1:
="" printf("\ncrc-error="" (nak-="">) !!\n");
break;
case 2:
printf("\nno response (DLE) !!\n");
break;
case 3:
printf("\nno send quitt (DLE) !!\n");
break;
case 4:
printf("\nReceive buffer overflow !!\n");
break;
case 5:
printf("\nrepeating telegram (->NAK) !!\n");
break;
case 6:
printf("\nno teststring defined\n");
break;
case 7:
printf("\nSTX\n");
break;
default:;
}
protocol_error = 0;
}
} while (!quit);
restore_8250 ();
setvect(sio_int_nr,oldvect_ser);
}
|
|
|
|
|
1. Use <pre> tags while posting code.
2. Post only relevent code, and describe what problem you are facing , nobody is going to see huge amount of code for you.
3. Ask is correct fourm. In this case its VC++[^].
Prasad
Notifier using ATL | Operator new[],delete[][^]
|
|
|
|
|
I have a program where u login to a lobby for games but theres no lobby or the games i need help.
I can post the code if needed
|
|
|
|
|
|
|
We have great big lumps of it round the back
led mike
|
|
|
|
|
Is this a C++/CLI question ? Are you saying you found source code onthe web and can't make it work ? Do you know how to program ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yes its a c++ question i am trying to learn how to code.
i got all of the parts i just need something that connects the programs
together.
like this is how i want it to work.
Login menu
goes to a game lobby where you are able to select the games i have made.
I just need help. Connecting them together.
|
|
|
|
|
I'm currently using 'fgets' to read a file like the sample below, and need to do some processing on it.....My first question is, is there a way for me to read the X,Y & Z data and store them into a multi-dimensional array? Secondly, the number of entries for the X,Y & Z data can vary from one file to another, so if an array is to be used, it has to be able to be sized dynamically.
using C++, Visual Studio 6.0
Any help would be greatly apperciated, thanks:
Sample File Data:
Name: Test
Date: mm/dd/yyyy
X Y Z
404.72 1064.42 60
402.224 1064.58 60
399.728 1064.75 60
Description: This is a test
//---------------------------------------------------------------------------------------------------------
Here is the code I have so far:
CFile importFile;
importFile.Open(fullName, CFile::modeRead);
CArchive ar (&importFile, CArchive::load);
if(!ar.ReadString(strLine))
{
importFile.Close();
return;
}
do // Repeat while there are lines in the file left to process
{
if( strLine.GetLength() == 0)
{ continue;
}
CString strText = strLine;
if(strText.GetLength() != 0)
MessageBox(strText,NULL,NULL);
}while(ar.ReadString(strLine));
//---------------------------------------------------------------------------------------------------------
|
|
|
|
|