|
Yes, You are the MAN. I spent a lot of time to find this problem.
Thanks
|
|
|
|
|
The following function is as follows
LONG ITCSCAN_GetDefaultDevice(
LPTSTR lpDeviceNameBuffer,
DWORD * pBufferLength)
with explanation as follows
lpDeviceNameBuffer [out] Pointer to buffer that will store the returned device name
pBufferLength [in/out]Pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the lpDeviceNameBuffer parameter. When the function returns, this variable contains the size of the data copied to lpDeviceNameBuffer
I under stand pointer points to address and I understand that dereference points to value at an address. But these Windows API functions have me confused, expecially with the out in/out stuff.
Can anyone make this clearer using the above function as example.
I would code
LONG defaultDevice;
LPTSTR deviceBuffer=NULL;
DWORD *bufferLength=NULL;
defaultDevice = ITCSCAN_GetDefaultDevice(deviceBuffer,bufferLength)
But that returns errors and when I've made changes to get the code to compile without errors I get access violation runtime errors.
Please Help!
|
|
|
|
|
egerving wrote: Can anyone make this clearer using the above function as example.
How about something like:
char deviceBuffer[1024];
DWORD bufferLength = sizeof(deviceBuffer);
LONG defaultDevice = ITCSCAN_GetDefaultDevice(deviceBuffer, &bufferLength);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
egerving wrote: Code does not work.
Based on your description David's code does exactly what is necessary; can you explain exactly what happens? Please remember to post your sample within the "code block" <pre></pre> tags to make it easier to read.
|
|
|
|
|
When I changed the char to TCHAR the code worked. I'm coding for windows ce and that was the difference.
Where I'm really confused it LPTSTR lpDeviceNameBuffer is pointer to a buffer to store the returned device name. How do I know what datatype to use for the buffer. It's not like
char *pdata is a pointer to
char data
because the datatype is LPTSTR
|
|
|
|
|
Its hard to say what your function does without seeing some documentation. But I suspect it is a dynamic sized buffer and when the functions fails it probably returns the size required. Something like this:
LPTSTR szBuffer = NULL;
DWORD dwLen = 0;
ITCSCAN_GetDefaultDevice(NULL,&dwLen)
if(0 < dwLen)
{
szBuffer = new TCHAR[dwLen];
ITCSCAN_GetDefaultDevice(szBuffer,&dwLen);
delete [] szBuffer;
}
Best Wishes,
-David Delaune
|
|
|
|
|
With regard to the above functions 1st parameter LPTSTR lpDeviceName [out] pointer to buffer that will store the returned device name.
What exactly does that mean? I think it means to declare a variable of type LPTSTR which is defined as a pointer to a buffer to store the returned device name. And the buffer is built into the function itself. Am I wrong?
Does is mean to actually delare a LPTSTR pointer and another buffer variable that it will point to?
|
|
|
|
|
Typically OUT means the function will write data OUT/into the buffer. The IN means the function expects data to be passed INTO the function. Can you guess what IN/OUT means?
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks. That make sense and that's what I thought. Can you help me with the dataTypes. I pretty confused on this. For example.
Function says LPTSTR lpDeviceNameBuffer is pointer to buffer. But what datatype must the buffer be. This is where I'm really having problems. It's not like
char data
char *pdata
where you know that the variable is a char and the pointer is a char.
|
|
|
|
|
LPTSTR is a Long Pointer to a TCHAR string. If your project has Unicode defined then the pointer will point to a WCHAR string. In an ANSI build it will point to a CHAR string.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you very much. I think I'm starting to get it now. The Wind32 Simple Data Types do actually tell you what all the various pointers are pointing to; ie, BOOL, BYTE, DWORD, CHAR, etc, etc.
|
|
|
|
|
|
Hi,
I want to ask you that what are the different manners to run a file auto in WindowsXP and Linux? Is auto run of any file is possible in Linux? Is there any other method in windowsXP to run a file auto(makeing a autorun.inf file)?
|
|
|
|
|
Hi
I can use "wifstream" to read strings. But I can not read number (using operator >>) back from a binary file.
it seems "wifstream" that "read" function work fine and its operator >> does not functioning.
Do you have any experience with "wifstream"? Could you share it with me?
Best
|
|
|
|
|
transoft wrote: Do you have any experience with "wifstream"? Could you share it with me?
This works for me:
void main( void )
{
wofstream out("c:\\data.dat", ios::binary);
out << 123;
out.close();
wifstream in("c:\\data.dat", ios::binary);
int x;
in >> x;
in.close();
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thank you very much.
I found out that "c:\\data.dat" is a text file.
I saved a number like "1". It should show in the binary file like "01 00 00 00" (using HexEditor). But your sample saved it as "1".
Thanks,
modified on Tuesday, November 3, 2009 2:01 PM
|
|
|
|
|
transoft wrote: But your sample saved it as "1".
Sorry about that. Can you just use the stream's write() method instead?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
But "Write" function can only write string to the file. The operator << suppose should be able to write number to the file. But it did not.
If you make a binary file using HexEditor like first 4 bytes looks like "01 00 00 00". Your sample can not read any thing back.
It is Microsoft fstream BUGs??? Or wifstream can only be used with text file?
|
|
|
|
|
transoft wrote: But "Write" function can only write string to the file.
It writes whatever is at the address provided to it, at least the ofstream method does.
ofstream out("c:\\data.dat", ios::trunc | ios::binary);
int y = 1234;
out.write((const char *) &y, sizeof(y));
out.close();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yes, Your sample works fine. But "read number" from binary file still does not work.
It is Microsoft VS 2005 BUG?
Thanks,
|
|
|
|
|
transoft wrote: But "read number" from binary file still does not work.
Are you using something like:
ifstream in("c:\\data.dat", ios::binary);
int x;
in.read((char *) &x, sizeof(x));
in.close();
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
How about "wifstream"? I have to use it in my Unicode application.
wifstream operator >> still does not work.
IS there a way to convert a TCHAR string to integer number or float number? It looks like I have to use "sscanf" to convert them. What a Microsoft JUNK!!!
Thanks,
modified on Tuesday, November 3, 2009 3:15 PM
|
|
|
|
|
transoft wrote: IS there a way to convert a TCHAR string to integer number...
Have you looked at _ttoi() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
My situation is that our users should be able to adjust their network settings (DHCP on/off, set static IP and set subnet mask) but I have yet to find a solution that is always reliable.
The following solution are from Google, but I think nothing are useful for me.
1. IP Helper API. Using AddIPAddress and DeleteIPAddress: Only adds an IP
address to the adapter, will not change the current one.
2. WMI using Win32_NetworkAdapterConfiguration: I don't want this solution.
3. netsh: Using CreateProcess and passing specail command line can do it, but I don't want to do by another process(Program).
4. DhcpNotifyConfigChange: Eidt registry and call DhcpNotifyConfigChange to notify change. The problem with DhcpNotifyConfigChange is that
it's an undocumented API.And if don't call DhcpNotifyConfigChange, you have to reboot your machine to take effect.
5. SetAdapterIpAddress. This solution are done well in Win2K and WinXP. It is not working under WinVista platform. This is an undocumented API. Using an undocumented API is never ideal
Any ideas? I just want to change IP,DNS,Getway and toggle DHCP without rebooting OS.This just like the Explorer.
|
|
|
|