|
Hi All,
I am porting a VC++ 6.0 application to VC++ 9.0. In this process i am getting these erors.
1. void CRoute::RestoreCurOrder(ComPtr<cworkorder> &pOrder)
{
XXX = pOrder.get();
}
error C3867: 'ComPt<t>::get': function call missing argument list;
use '&ComPtr<t>::get' to create a pointer to member
2. _bstr_t func("CScreenDlg::GetDataField(" + tableName + "." + fieldName + ")");
TRACE(func + ": Table not found"); //#define TRACE ATLTRACE//
error C3066: there are multiple ways that an object of this type can be called with these
arguments
Any suggestions will help me fixing the issues.
Thanks.
|
|
|
|
|
Well, VC6 is a hideous disaster, and MFC has changed. Your code must have been very good for these to be the only errors you get. The first error looks to me like the only visible get method expects parameters. The second looks like it can't work out what sort of string you have, so try building the string first and passing in as a specific type of string, such as a BSTR, a CString or a char *.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi,
The second got resolved, but the first problem get() method has no parameters.
Regards,
Ramahcandraraju KK
|
|
|
|
|
I am not sure when we use an UDP socket to send and receive messages from one windows application to a mobile device that uses a modem and SIM card, where a port be assigned to an IP. say I have a SIM card with fix IP xxx.xxx.xxx.xxx, when I send a message I get it in my Windows base app as coming from that IP and a big port number (i.e. 48618). The SIM card provider suggests that they don't assign any port number to a SIM card. the thing is that after a while the port number gets changed if there is no traffic and My application can't send a message to the device as I send to the IP and the port that I got the last message from.
Best,
Nahita
|
|
|
|
|
If there is an application on that mobile device that you want to communicate with, you have to have the specification for communicating with the application, you can't just guess at how to do it. Do you have the specification?
led mike
|
|
|
|
|
I can communicate with the application to the mobile device fine. My problem is that the port gets changed time to time and I was wondering if anybody knows where a port gets assigned in GPRS for a UDP socket.
Thanks,
|
|
|
|
|
A port represents a way to identify which specific process a packet is addressed for on a system where multiple processes share the same network connection. Therefore ports are generally an application level mechanism. If the mobile device does not use this typical approach then I don't know what it uses, but someone does that would be related to that specific device. In a typical use of a TCP/IP stack the application can choose to be assigned a random port from the stack. In that case the "where" is in the TCP/IP stack code.
Either way, I don't understand how knowing "where" the port assignment occurs helps you do anything about it. That aspect of the mobile devices system is not going to be exposed to your remote application. You will have to use the specifications for that device/application, as I previously stated, for communicating with it/them, period.
led mike
|
|
|
|
|
nahitan wrote: the thing is that after a while the port number gets changed if there is no traffic
Can't you ping the device time to time? I supose when there is no communication for a while it will "timeout" and close the socket or whatever it uses and when it has something to send it will create a new one, send the message from there and keep it up again for a while. But if you don't let it timeout it might stick to the original port.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
to maintain a port you need to send a ping every 45 seconds that is a lot of data and if you have 2000 devices, that would be a big number. I am just wondering where a port gets assigned.
Thanks,
|
|
|
|
|
If there is no fix port number you can communicate with, how do you make a "connection" (i know it is connection less UDP) to the device the first place?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
When reading a binary file, and you have no clue what the delimeter may be, since you only care about the raw number of bytes you read, and yes there are thousands of \n's in the file for some reason.
Is there a single function that can do that without specifying what the delimeter is or do I have to read this character by character?
|
|
|
|
|
there are functions that ignore the data completely. What is it you are using right now?
Maybe you could show some code...
|
|
|
|
|
<br />
char* buffer = new char[settings.getAccessesToSimulate()];<br />
char* fname = settings.getFileName();<br />
<br />
ifstream binFile(fname, ios::in|ios::binary);<br />
<br />
if(!binFile)<br />
{<br />
}<br />
<br />
binFile.read(buffer,settings.getAccessesToSimulate());<br />
<br />
binFile.close();<br />
<br />
I also tried, get and getline after that with the same results. After this little beauty runs, I get buffer = "gsA" which is incorrect since I'm giving it 1000 characters to read. Opening the file manually (in windows, not linux where its supposed to be) shows me that there's an NUL right after those three characters (they're actually hex).
|
|
|
|
|
Mustafa Ismail Mustafa wrote: After this little beauty runs, I get buffer = "gsA" which is incorrect since I'm giving it 1000 characters to read. Opening the file manually (in windows, not linux where its supposed to be) shows me that there's an NUL right after those three characters (they're actually hex).
But what is there in buffer **after** the NULL? You're displaying buffer as a C string, so printf (or whatever) sees the NULL and presumes that's the end of the data in buffer . It probably *isn't*. The trouble is that the C string semantics get assumed for any char* , but those aren't the semantics you want.
You probably ought to iterate through buffer with a for-loop or something to see the data after the NULL.
|
|
|
|
|
That's what I did. Buffer only contains those 3 characters. I know the file has 4,000,000 bytes of data that I need extracted.
I'll be more than happy to change the implementation to something else. I'll just need to be pointed in the right direction
|
|
|
|
|
I've just built your code into a small executable and read a file containing the following text:
48 65 6C 6C 6F 00 48 65 6C 6C 6F
That's two instances of the word 'HELLO' separated by a NULL. I looked at the contents of buffer using the 'Examine Memory' feature of WinDbg and it contained the 11 bytes shown above. That's what you wanted to achieve, no?
|
|
|
|
|
Precisely. So why is my buffer reading 4 bytes (the 3 characters and the terminator) before exiting? Any ideas?
|
|
|
|
|
One other thing I can think of - what's the value of settings.getAccessesToSimulate() ? We've shown that your file reading code is correct - but are you reading the right number of bytes?
|
|
|
|
|
Sorry for the late reply.
That was the first thing I checked and after I did get it fixed ( I wasn't making a constant reference of all things!) the number currently I'm using is 1000 though it could range from 0 to 1,000,000.
This is on Fedora if it makes any difference though it should not.
|
|
|
|
|
I've just tried your code on OS X - worked fine there as well.
One last suggestion - you could try using the C file handling functions (open , read , close ), like so:
int fd = open(fname, O_RDONLY);
const int nBytesRead = read(fd, buffer, 1000);
close(fd);
That at least tells you how many bytes it's read?
[edit]In Visual C++, this probably ought to be:
int fd = _open(fname, _O_RDONLY|_O_BINARY);
const int nBytesRead = _read(fd, buffer, 1000);
_close(fd);
VC++ uses the "ISO C++ conformant" names rather than the POSIX API names...ho-hum.
[/edit]
On the same note - std::ifstream has a method called gcount that tells you how much the last read actually read:
binFile.read(buffer, 1000);
std::cout << binFile.gcount() << std::endl;
Just tried both of those on OS X - both give the expected results with files that contain embedded NULLs.
modified on Thursday, December 11, 2008 7:00 PM
|
|
|
|
|
This is insane.
After restarting the computer, things worked perfectly, the way they should have in the first place. Why would something like this happen?
Thanks much Stuart, you and rest helped, and I got to (re)learn a few more things.
Cheers
|
|
|
|
|
Mustafa Ismail Mustafa wrote: After restarting the computer, things worked perfectly
Don't you hate computers sometimes - as recalcitrant as a small child
|
|
|
|
|
Stuart Dootson wrote: Don't you hate computers sometimes
With extreme prejudice. I have a computer that I'd like to introduce to a baseball bat at 90mph. One day I will, instead of relegating it to our family "museum".
I have a slightly different thing now. Bear with me, its been a few years since I've worked this "heavily" with C++.
A different binary file, is being read and this time, I need to clump every 4 bytes into one structure and this structure would be a member in an array of its type. Suggestions?
|
|
|
|
|
Mustafa Ismail Mustafa wrote: A different binary file, is being read and this time, I need to clump every 4 bytes into one structure and this structure would be a member in an array of its type. Suggestions?
Pffff - kind of depends on a lot of things , like:
- Does the file have the same endian-ness as the computer you're working on?
- Do you know how many elements the array has?
- What format is the 'structure' you talk about?
Possible solutions include:
- Interpreting the file byte-by-byte, to read into the structure
- Read the file a structure (four bytes at a time), assuming that the structure can be represented as four contiguous bytes in memory. I'd use
#pragma pack to do that, with a static assert[^] to ensure that the structure really takes up four bytes in memory. If endian-ness is an issue, then you can reverse bytes at this point. - Read the whole array in, if you know how many members it has. To ensure that padding doesn't get in the way, you could read in the correct number of bytes (
sizeof structure * element_count ), then use a byte pointer to step through the bytes, casting the pointer to a structure pointer when accessing the bytes
Yes, I've done this stuff a fair bit. From reading and interpreting executables (not just PC ones - that's where the different endian-ness has come in) through decoding data received over a serial link to reading and interpreting gigabyte-sized data files logged when testing embedded systems.
I generally use memory-mapping so I don't need to bother with reading the files myself. In the case of gigabyte size files, this means mapping different bits of the file at different times, 'cause there's not enough RAM/address space to map the whole thing at once.
I find that using custom iterators (with the help of the Boost Iterator library[^]) helps, as you can abstract the conversions/file access/pointer incrementing into the iterator, allowing you to concentrate on the structures you're actually reading from the file. This especially helped with the big memory-mapped file thing, as I could hide the mapping/unmapping of the file, and (in effect) get a random access iterator over the file that meant I never had to deal with the file *as a file*. That was sweet - maybe I ought to write an article about it.
In general, I'd advise using layering in your application's architecture, so you deal with the details of the binary file *in a single, self-contained place*, allowing you to deal with higher-level concepts withouyt worrying about the lower-level ones.
|
|
|
|
|
I solved it by reading a 4-byte chunk at a time, throwing that into the struct of the array at that point and updating the pointer using seekg();
Thanks for everything Stu. If you ever come Jordan ways, look me up, I'll stand you a couple of pints
|
|
|
|