|
Hello everyone,
Anything wrong with my code below? I got the compile error!
typedef unsigned char BYTE;
void foo(char* & p)
{
return;
}
int main()
{
BYTE * buffer;
foo ((char*)buffer);
return 0;
}
thanks in advance,
George
|
|
|
|
|
this isnt strange as foo required char*& and not char*.
Don't try it, just do it!
|
|
|
|
|
My confusion is reference type is the same as original type, for example when type Foo is needed, we could pass Foo or pass Foo&. So, I think then char* & is needed I could pass char*? What is wrong with my understanding?
|
|
|
|
|
BYTE is an unsigned char (8 bit)
char* is a pointer (32 bit)
When converting BYTE to char* then it needs to create a temporary variable. It is not possible to make return-by-reference with temporary variables.
Instead make the conversion from BYTE to char* by using a local variable, and then pass that local variable to the function.
|
|
|
|
|
I agree with your points, but confused. Since I am using BYTE* not BYTE.
Anyway, could you show me your code please? I think code clarifies everything.
regards,
George
|
|
|
|
|
Where is he converting a BYTE to char*? He's converting a BYTE* to char*. In other words, unsigned char* to char*. I think there's no problem with the pointer size.
this is enough:
foo ((char*&)buffer);
|
|
|
|
|
It's all to do with the semantics of casting - you can't pass a reference to something you've produced with a cast, even if the size and location of the thing is the same.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You must call it as below
char* pp = (char*)buffer;
foo(pp);
«_Superman_»
|
|
|
|
|
Your code fixes my issue, but why? I think both your code and my code are of the same effect.
regards,
George
|
|
|
|
|
When you typecast, you have to give the destination exactly as it should be.
So you could also typecast if as foo((char*& )buffer)
«_Superman_»
|
|
|
|
|
It's all to do with the semantics of casting - you can't pass a non-const reference to something you've produced with a cast, even if the size and location of the thing is the same.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hi,
I have an application which loads some images. when I changes the screen resolution position of images gets changed. How to manage image position while changing the screen resolution.
Thanks
|
|
|
|
|
what images? where are they displayed? how are they displayed?
Don't try it, just do it!
|
|
|
|
|
You can check new resolution with GetSystemMetrics.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi,
I created an C++ application an run Excel within that application by using the COM-Interface. For the development I use Visual Studio 2005. At the moment I'm be able to create an Excel application, create a worksheet and put Data on selected cells. Just see my code example.
Excel::_ApplicationPtr ExcelApp;
ExcelApp.CreateInstance(L"Excel.Application.9");
ExcelApp->put_Visible(10, true);
Excel::_WorksheetPtr pSheet;
pSheet = ExcelApp->ActiveSheet;
pSheet->Range["C1"]->Value = "Hallo World";
ExcelApp->Quit();
Now I'm trying to create a Excel ListBox throughout my C++ application. The problem is, that I'm not a experienced programmer. By searching the internet, I couldn't found any examples which would explain how to do that. In the excel9.tlh include, I found a ListBox decleration. The problem is that I don't know how to instantiate such a struct and conect it to a defined cell.
Thanks for your help.
|
|
|
|
|
After following the great tutorial on here: <a href="http://tldp.org/LDP/LG/issue74/tougher.html">http://tldp.org/LDP/LG/issue74/tougher.html</a>[<a href="http://tldp.org/LDP/LG/issue74/tougher.html" target="_blank" title="New Window">^</a>]
sources in folder here: <a href="http://www.sharedigest.com/SocketClientServer.zip">http://www.sharedigest.com/SocketClientServer.zip</a>[<a href="http://www.sharedigest.com/SocketClientServer.zip" target="_blank" title="New Window">^</a>]
I've managed to get the client and server talking to each other.
This is for an setup whereby data will be transmitted to my client via telnet from a remote server, and, according to them, I need to configure the client in such a way that it checks if the server dies and automatically attempts to reconnect after some (pre-specified) time period.
Currently, when I kill the server, I get ALOT of '' received by the client, continuously ... (output shown below, main routine shown below output)
I was wondering if there's a way to detect that the connection from the server's been lost, and consequently attempt to reconnect and keep listening for incoming messages?
Help much appreciated!
gvanto
socket newbie
<code>
Server:
pacific@mainbox /workspace/SocketClientServer/Debug$ ./SocketClientServer 0
starting server ...
Hello server from client.
Please enter string to send: hello back to client
Please enter string to send: another message
Please enter string to send: one more
Please enter string to send: //here i kill the server using ctrl+c
Client:
pacific@mainbox /workspace/SocketClientServer/Debug$ ./SocketClientServer 1
starting client ...
Sending hello server msg ...
Listening ...
We received this response from the server:
"hello back to client"
Listening ...
We received this response from the server:
"another message"
Listening ...
We received this response from the server:
"one more"
Listening ...
We received this response from the server: //AFter server killed, FLOOD of incoming BLANK messages received by client
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
</code>
MAIN ROUTINE:
<code>
/*
* main.cpp
*
* Created on: 15/02/2009
* Author: pacific
*
* http://tldp.org/LDP/LG/issue74/tougher.html
*/
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include "ServerSocket.h"
#include "ClientSocket.h"
#include "SocketException.h"
#define DO_MAIN 1
using namespace std;
#ifdef DO_MAIN
int main(int argc, char *argv[]) {
if(argc > 1) {
/*****************************************************
* *********** SERVER *******************************/
if(atoi( argv[1] ) == 0) { //server mode
cout << "starting server ... " << endl;
try {
//Create the server socket
ServerSocket *server = new ServerSocket(30000); //set up socket and listen on local port
while(true) { //wait for incoming connections
/**
* Contains all of our socket information, used to exchange data with the client.
*/
ServerSocket new_sock;
server->accept(new_sock); //accept new incoming socket connection
try {
while(true) {
string data;
new_sock >> data; //read data from new_sock into 'data'
cout << data << endl;
//new_sock << data; //sends data in 'data' back throught the socket to the client (echo server)
string sendstr;
while(1) {
cout << "Please enter string to send: ";
getline (cin, sendstr);
new_sock << sendstr; //send it!
}
}
}
catch(SocketException&) {}
}
}
catch(SocketException &e) {
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
}
/*****************************************************
* *********** CLIENT *******************************/
if(atoi(argv[1]) == 1 ) { //client mode
cout << "starting client ... " << endl;
try {
//Create the server socket
ClientSocket client("localhost", 30000); //set up socket and listen on local port
string reply;
try {
cout << "Sending hello server msg ... " << endl;
client << "Hello server from client. "; //send
}
catch(SocketException &) {}
while(true) { //keep listening
try {
cout << "Listening ... " << endl;
//client << "Test message. "; //send
client >> reply; //receive
}
catch(SocketException &) {}
std::cout << "We received this response from the server:\n\"" << reply << "\"\n";;
}
}
catch(SocketException &e) {
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
}
}
else {
cout << "usage: ./SocketClientServer 0|1 (0 == server, 1 == client)" << endl;
}
return 0;
}
#endif
</code>
Find Your Dream IT-Job in Australia, Free!
http://www.WebCV.com.au
|
|
|
|
|
Go back to Beej's networking guid that you were looking at a few days ago - that says this in the section about recv
Wait! recv() can return 0. This can mean only one thing: the remote side has closed the
connection on you! A return value of 0 is recv()'s way of letting you know this has occurred.
[edit]I'd modify the ClientSocket class to do something like throw an exception on getting a return value of zero from recv .[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks alot, think the recv() == 0 should do the trick.
I've set it up to be reconnecting every somany seconds, when it does it keeps listening.
Many thanks again guys,
onto threads now!
(multiple clientsockets within class)
|
|
|
|
|
It simply sucks to go through the junk. Please remove it.
Also, to answer your question, based on my guess, I think you are not talking about a natural disconnect between server & client. TCP is connection oriented, when one breaks it , you should get an exception. But there's one exception, when there's a slight network disruption, the server actually loses it's connection with client, but it acts to be there alive. The client gets notified but the server don't. even the send function wouldn't convey us anything.That's a problem. There we need to set up a ping mechanism. The server asks "Are you all alive".. the clients say "Yes we are". If few client's don't say, they are actually out. We need to remove them from association with server.
I don't remember the scenario so clearly. I did these long before. I'm not sure If I'm right :P. A couple of years before I replied to the same question with a more vivid answer. lol memory's fading.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Please tell me what will the cause for this.
i have checked the path for MIDL compiler also. Please help
|
|
|
|
|
This error can occur in many cases:
- The type library could not be generated. One possible cause of this error is specifying a path to the IDL file that is longer than 126 characters. Oleaut32.dll does not support path names longer than 126 characters.
- Another way to get this message is to have the .tlb file write-protected, as you do when you use a code management tool...
I think that you first have to check your .tlb files if you use some code management tool
|
|
|
|
|
I am getting an error as said in the subject line . I know this is because i am porting my code from VC 6.0 to .NET 2005. But dont know how to troubleshoot this problem. Can you please tell me is there any setting required for this ...because my other adddins are building properly except for one i am getting such an error.
|
|
|
|
|
Sounds to me like the add-in is verifying that it's being built for VC++ 6. If you're porting the add-in to VC2005, then you need to remove that line as part of the porting process...
But if it's really that tied to VC++6, you're going to have real problems porting it to VC2005, as the add-in model's changed big time between the two versions, I think.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
yes that adding was built for VC++6.0.. that code is of CPPUnit for making the Unit Test script for new feature development.
Now i have "Batch Builded" my framwork of CPPUnit. The error in subject line doesnt occurs instead a new one is generated like this
"Error 44 error PRJ0019: A tool returned an error code from "duplicating DLL to lib directory" DSPlugIn"
Error 43 Could not delete file 'd:\CPPUnit\cppunit-1.12.1\src\msvc6\DSPlugIn\TestRunnerDSPlugin.tlb'.
Make sure that the file is not open by another process and is not write-protected. DSPlugIn
kindly provide the comments so that i can resolve the issue..
Thanks
|
|
|
|
|
Sounds like you have the addin open somewhere - are you using VC6 with the CppUnit at the same time?
Also - things I've read (including the source-code - src\msvc6\testrunner\MsDevCallerListCtrl.cpp in the latest source tarball) imply that no add-in is required for Visual Studio later than VC6. The add-in is used to support jumping to source code when double-clicking on an error in the MFC test runner, something that can be accomplished without the plug-in for later Visual Studio editions.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|