|
thx for the help
-Raffi
|
|
|
|
|
Hi:
In a CFormView-derived view, I can change control colors by handling WM_CTLCOLOR messages.
What can I do to change control colors for a CView-derived view?
Thanks
|
|
|
|
|
Whether CFormView or CView derived does not matter, simply override OnCtlColor(...) [which is called when a WM_CTLCOLOR message arrives].
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Like Nish said, this is where you want to do it. You can use the nCtlColor variable to check for what kind of control it is and then send back a different HBRUSH for different controls to control the color.
|
|
|
|
|
Hi.
I am new to winsock program and has began study from Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohlund.
I am trying to get a code to basically resolve a hostname to its ip address. For example:
-----
user input: www.microsoft.com
app output: 207.46.230.220
-----
I am able to get the calculation above working using older winsock 1.1+ tool including the use of structure hostent, gethostbyname(), and inet_ntoa().
However, in their book, Jones and Ohlund recommend using the newer winsock tools including getaddrinfo() and getnameinfo(). I cannot figure out how to extract the corresponding IP address from a hostname. Here is the code:
-----
int rc = 0;
addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (getaddrinfo(rHName, "21", &hints, &result) != 0)
return false;
else
{
// This is where I need help getting the IP address
m_sIP = (reinterpret_cast<sockaddr *="">(result->ai_addr)->sa_data());// ->sa_data(); // inet_ntoa(*(reinterpret_cast<in_addr *="">(host->h_addr)));
return = true;
}
-----
In the code above, m_sIP is a character array. What do I have to cast result->ai_addr in order to access the IP address?
Thanks,
Kuphryn
|
|
|
|
|
Here is the solution to my original problem.
-----
{
m_bVeri = false;
addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (getaddrinfo(static_cast<lpctstr>(rHName), m_sPort.c_str(), &hints, &result) != 0)
return m_bVeri;
if (getnameinfo(result->ai_addr, result->ai_addrlen, m_sIP, 256, NULL, 0, NI_NUMERICHOST) != 0)
return m_bVeri;
m_bVeri = true;
freeaddrinfo(result);
return m_bVeri;
}
Kuphryn
|
|
|
|
|
Hi,
It appears I ran into a bit of a contradiction.
According to the documentation for CInternetSession, you should be able to make your internet operations asynchronous and set up a callback to report on the status of the operations.
One of the requirements for this, is that:
In the CInternetSession constructor, dwFlags must include INTERNET_FLAG_ASYNC.
However, the first line of code in that constructor is:
ASSERT((dwFlags & INTERNET_FLAG_ASYNC) == 0);
My logical skills may be failing me, but that code tries to assert that dwFlags does NOT include INTERNET_FLAG_ASYNC, right?
So I have to set the flag, but I'm not allowed to set the flag. What's up with that? Or am I missing something?
All input appreciated,
Ren
|
|
|
|
|
I thought I had the answer for you because I have done a project that used CInternetSession for FTP and had to be asynchronous. After looking at that project it turns out that I used a thread. This would be a valid option for you if you can't find another way. If you decide to go with threads I can give you some sample code.
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
I too ran into this problem earlier. Turned out the the docs on the MSDN CD are old/incorrect. See the latest online docs for CInternetSession .
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
It's alive! Beautiful, guys!
Finally some light at the end of the tunnel (no thanks to the msdn librarians. Oh, how they torture us...)
I wouldn't mind getting some threading sample code, though. It's not really an essential requirement of my project, but why aim for less than perfect?
Thanx a bunch,
Ren
renegade@killatactics.com
|
|
|
|
|
Using CPropertySheet, is there anyway to change the text of the Cancel button?
|
|
|
|
|
pSheet ->GetDlgItem (IDCANCEL) ->SetWindowText ("New Text");
That is assuming pSheet is a pointer to your sheet.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim,
I don't know how to do this with CPropertySheet. It gives you the 4 wizard buttons (Back, Next, Cancel, Help) automatically with member functions to manage them. See SetWizardButtons in MSDN. You don't have direct access to the buttons. I don't see a way to change the text on the Cancel Button.
Bob
|
|
|
|
|
Those buttons are just like any other button on a dialog. Get the window and then set the window text.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi,
I'm new to writing a service and I've found the following psuedo code for my main function:
for (int i = 1; i < argc; i++)
{
if ((argv[i][0] == TEXT('-')) || (argv[i][0] == TEXT('/')))
{
// Command line switch
if (lstrcmpi(&argv[i][1], TEXT("Service")) == 0)
InstallService();
if (lstrcmpi(&argv[i][1], TEXT("UnRegServer")) == 0)
RemoveService();
if (lstrcmpi(&argv[i][1], TEXT("debug")) == 0)
{
// Execute the service code
ServiceMain(0, NULL);
}
if (lstrcmpi(&argv[i][1], TEXT("service1")) == 0)
{
// Connect to the service control dispatcher
SERVICE_TABLE_ENTRY ServiceTable[] =
{
{ g_szServiceName, ServiceMain },
{ NULL, NULL } // End of list
};
chVERIFY(StartServiceCtrlDispatcher(ServiceTable));
}
}
}
From looking at this code, in order to install and start the service, I would have to call the application passing in -Service then -service1. Is there any way that I can just call -Service then make a call to net start service_name.exe?
Thanks for any help you can provide,
Craig
|
|
|
|
|
Here is what is going on...
When you type the command "XXXX -Service" the program is creating the entry in the service database for your service. One thing you don't see here is that when it creates the entry in the database it is specifying " -Service1" as the command line for the service.
THUS, when you start the service via the control panel or the net command, it is automatically run as "XXXX -Service1". Thus the program sees the "-Service1" parameter and knows that it is being run as a service and not interactively.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim,
Thanks for the reply, that seems to make sense but when I do the following at the command prompt this is what I get:
C:\Temp\MyService\Debug>MyService -Service
C:\Temp\MyService\Debug>net start MyService
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
I think this is happening because StartServiceCtrlDispatcher(...) isn't getting called because it never get's to:
if (lstrcmpi(&argv[i][1], TEXT("service1")) == 0)
{
// Connect to the service control dispatcher
SERVICE_TABLE_ENTRY ServiceTable[] =
{
{ g_szServiceName, ServiceMain },
{ NULL, NULL } // End of list
};
chVERIFY(StartServiceCtrlDispatcher(ServiceTable));
}
I'm not sure if this is actually the case but I think it is. Do you have any ideas about this?
Thanks,
Craig
|
|
|
|
|
If what I am thinking is correct, do this.
Run REGEDIT.
Locate the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YOUR_SERVICE_NAME
Under that key should be the command line used to start the service stored in the "ImagePath" value. Check to make sure that it looks something like:
"C:\DIR\DIR\DIR\YOUR_SERVICE_PROGRAM.EXE -service1"
If "-service1" is missing, then just as a test, add it to the end of that value. The try the NET START command again. If it works then, make sure that the code creating the service includes the "-service1" string.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim,
That is EXCELLENT, you've probably save me a couple days worth of work. Do you happen to know off the top of your head how I can change the default value of that registry setting inside the service? Or, do I have to just manually change that when I install the service?
Thanks again for all your help with this,
Craig
|
|
|
|
|
You shouldn't have to do anything special. Just take a look at your service creation code (look for the CreateService API routine). Instead of just specifying the program name for the 8th argument, append " -service1" to the end of that string and then call CreateService. That should get it done.
Now if the service already exists, you will have to invoke OpenService and then ChangeServiceConfig. In my code I just blindly call CreateService. If it returns ERROR_SERVICE_EXISTS or ERROR_DUP_NAME, then I call OpenService and ChangeServiceConfig to change any service settings.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim,
That did the trick. Thanks so much for taking the time to help me with this. I now have a running service .
Thanks again and have a great weekend,
Craig
|
|
|
|
|
Hi
i recently created a completely new hash algorithm "UFH" (Ultra Fast Hash).
This algorithm works relatively simple:
1) fill a hash-byte-array by simply adding the data bytes to the bytes in the array
2) if the end of the array is reached, perform as many PHTs (Pseudo-Hadamard-Transforms) as needed to spread a single bit error over the complete array (for example if the hash length is 4 bytes you have to perform 8 PHTs, 4 forward, 4 backward).
A 8-bit PHT is defined as
x += y
y += x
The hash algorithm is definitely not usage in cryptography, but to check if a file is original the algorithm seems to work very well.
You can download it here.
Please download it and test it.
I am really interested in you opinion. If you think it is well, i perhaps write an article about it.
Thank you very much
Dominik
|
|
|
|
|
Take a look at CRC32. It is very good at detecting errors and works very well at detecting change. If you need even better change detection, MD5 works well.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I know CRC32 and MD5 (and many more). But MD5 is a cryptographic hash function and it seems that my algorithm is at least as fast as CRC32 and when using longer hashes it seems to be more secure than CRC32. It seems that if increasing the hash size the speed doesn't slow down.
Have a look at the sample.
|
|
|
|
|
Ok, I have found many failures so far.
1. The following two data streams match (all bytes processed in one UFH_HashIn)
unsigned char szData1 [] = { 1, 0x80, 2, 3, 1, 0, 2, 3 };
unsigned char szData2 [] = { 1, 0, 2, 3, 1, 0x80, 2, 3 };
2. These two data streams match (all bytes processed in one UFH_HashIn)
unsigned char szData1 [] = { 0 };
unsigned char szData2 [] = { 0, 0 };
3. These two data stream match (all bytes processed in one UFH_HashIn). This is really a variant on #2.
unsigned char szData1 [] = { 1 };
unsigned char szData2 [] = { 1, 0 };
4. The routine is very depending on how a stream is processed. Given the following stream, if 5 bytes are processed followed by 3 to generate the first hash, and then all 8 bytes are processed to generate a new hash, the resulting values do not match. Thus giving you a false failure to match.
unsigned char szData1 [] = { 1, 0x80, 2, 3, 1, 0, 2, 3 };
Many of the problems you have are the exact problems that CRC-32 try to fix. Now even CRC32 can have a problem with test case #2 *IF* a value of 0 is used for the seed. But the other failures wouldn't happen with CRC32.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|