|
Hi. I am sure this has been asked a few times but i cant find any clear code for this. i am using the curl classes to download data from a HTTP server, is there any ready code for requesting HTML and that the function returns that? (Not through a callback function)?
Thanks
|
|
|
|
|
Not sure what cURL classes you're using as there's plenty kicking around but if you're using the easy interface: curl_easy_getinfo with a code of CURLINFO_RESPONSE_CODE will give you the response code for a given transfer. Or zero if the headers haven't been recieved yet.
Cheers,
Ash
|
|
|
|
|
Through some standards an experience, I tried to put this Magic Packet application together.
However it doesn't wake up the machine, nor does the Wake On LAN tutorial on CP succeed in accomplishing the same task.
#include <winsock2.h>
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void main()
{
char MAC[13];
cout << "Enter MAC Address for Machine to wake up:" << endl;
cin >> MAC;
cout << "Waking up..." << endl;
char L = (char)255;
cout << L << endl;
WSADATA WS2Info;
if (!WSAStartup(MAKEWORD(2,2), &WS2Info))
{
SOCKET MagicPacket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (MagicPacket != INVALID_SOCKET)
{
hostent *ResolveHost;
char* HostAddress = "";
ResolveHost = gethostbyname(HostAddress);
SOCKADDR_IN Host;
Host.sin_family = AF_INET;
Host.sin_port = 0;
Host.sin_addr.s_addr = *((unsigned long*)ResolveHost->h_addr);
short MACconv[6];
memset(MACconv, '\0', 6);
bool FirstDigit = true;
int Pos = 0;
for ( int i = 0; i < 12; i++)
{
switch(MAC[i])
{
case '0':
if (FirstDigit)
{
MACconv[Pos] = 00000000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000000 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '1':
if (FirstDigit)
{
MACconv[Pos] = 00010000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000001 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '2':
if (FirstDigit)
{
MACconv[Pos] = 00100000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000010 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '3':
if (FirstDigit)
{
MACconv[Pos] = 00110000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000011 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '4':
if (FirstDigit)
{
MACconv[Pos] = 01000000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000100 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '5':
if (FirstDigit)
{
MACconv[Pos] = 00010000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000001 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '6':
if (FirstDigit)
{
MACconv[Pos] = 01100000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000110 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '7':
if (FirstDigit)
{
MACconv[Pos] = 01110000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00000111 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '8':
if (FirstDigit)
{
MACconv[Pos] = 10000000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001000 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case '9':
if (FirstDigit)
{
MACconv[Pos] = 10010000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001001 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'A':
if (FirstDigit)
{
MACconv[Pos] = 10100000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001010 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'B':
if (FirstDigit)
{
MACconv[Pos] = 10110000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001011 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'C':
if (FirstDigit)
{
MACconv[Pos] = 11000000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001100 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'D':
if (FirstDigit)
{
MACconv[Pos] = 11010000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001101 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'E':
if (FirstDigit)
{
MACconv[Pos] = 11100000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001110 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
case 'F':
if (FirstDigit)
{
MACconv[Pos] = 11110000 | MACconv[Pos];
FirstDigit = false;
}
else
{
MACconv[Pos] = 00001111 | MACconv[Pos];
FirstDigit = true;
Pos += 1;
}
break;
}
}
short WakeUpMsg[103];
memset(WakeUpMsg, '\0', 103);
memset(WakeUpMsg, 255, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
sendto(MagicPacket, (char*)WakeUpMsg, 128, 0, (SOCKADDR *)&Host, sizeof(Host));
}
}
}
Code Free for Non Commercial Use!
|
|
|
|
|
Fareed Rizkalla wrote: memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
memcpy(WakeUpMsg, MACconv, 6);
All these lines are repeatedly copying the first 6 bytes of MACconv to the first 6 bytes of WakeUpMsg ; you need to use some form of index or offset to fill the packet correctly.
It's time for a new signature.
|
|
|
|
|
Hi All,
1) I want to send some data to a C# Application which has WPF controls (like text box) in it.
2) I also want to read the data from the WPF control (text box) to the VC++ application.
I tried using SendMessage API, but I don’t know how to get the textbox handle.
I found UI Automation is one solution for this but I found examples for C# only. I couldn't find any examples on UI Automation for VC++.
Please provide me some input on this.
Thanks,
Joseph
|
|
|
|
|
Joseph82 wrote: I tried using SendMessage API, but I don’t know how to get the textbox handle.
WPF controls don't have handles only window has a handle.If you would like to use SendMessage API you should consider using windows forms controls combined with WindowsFormsHost.See here how http://msdn.microsoft.com/en-us/library/ms742875.aspx[^]
Using automation is more difficult, but there's lots of samples just point "MFC automation samples" in google.
Life is a stage and we are all actors!
|
|
|
|
|
Hi all,
We have a client/server (C/C++/MFC/Win32) application that historically has used an internal table for managing users/passwords/product permissions etc. We've had a request from a customer to manage these types of things via Active Directory and take advantage of Single Sign-on etc.
I know very little about Active Directory since we don't use it here in our office, but I've done a fair amount of reading and managed to set one up in a VM for testing purposes.
Questions:
1) Since much of our product depends on OUR UserID table and we have some customers that want to use AD , I'm thinking we should be importing account information FROM Active Directory periodically. Does this sound right?
2) When a user logs in - I should be authenticating the user through Active Directory and NOT our internal mechanism?
3) Does Active Directory have a means for me to define a list of permission options that the ADMIN can manage? ie: Add Record, Delete Record, Update Record, that I can check against when one of these operations are performed in our product.
4) I have found a lot of AD code in C# but, having a harder time finding stuff in C++. Anyone have any good examples?
Anything you could forward my way would be greatly appreciated.
Cheers.
Mike.
|
|
|
|
|
The Active directory (AD) is an architecture where domains (containers of users groups, resources and access lists) derives each other hierarchically into forests and trust each other between forest. The way they do this depends on how the managers of your client organization organize their information system, and -ideally- the AD architecture either by domain derivation or trusteeship, can span the world.
Think to the AD as a "generalized DNS for users". You cannot download the entire DNS to get an IP address, hence you cannot pretend to download the AD.
You must instead query the AD.
You application should NOT contain any "user login". You simply should get who is the user actually on a machine by simply query proper OS API (GetUsername ... or similar, nor shure about it, but MSDN may help) and to decide if the user can do or not a given operation you must check if such a user is part or not a given user group (The API should be IsInRole ... or something similar).
The name of the groups corresponding to your app privileges, should be loaded by a config file (the domain administrator will typically place it in a read-only place) and should be defined by the domain admin itself.
This is a minimum way to start with. And is valid -as a concept- also for a stabdard LDAP server - non necessarily AD
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Thanks for your reply - much appreciated.
I'm finding lots of code related to group membership (IsInRole etc) for C#, but not a whole lot in Win32, any help?
Also, is there a way I can query for a list of users in the group?
Again, thanks alot for your reply.
M.
|
|
|
|
|
Mike Doner wrote: I'm finding lots of code related to group membership (IsInRole etc) for C#, but not a whole lot in Win32
There is a chapter o the MS-SDK called "Security" that describe all the aspects, including "Authentication" and "Authorization", that also have sections bout C++. It's all about COM objects. That's why they have mostly C# wrapper: COM is natively marshaled into .net
give a look to http://msdn.microsoft.com/en-us/library/aa375769%28v=VS.85%29.aspx[^]
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Is INT_PTR available in VC++ 2010? Is it safe to use instead of int in places like getting return value from CDialog::DoModal() etc?
--
"Programming is an art that fights back!"
|
|
|
|
|
Yes, the INT_PTR is available in VC++ 2010, and not only it's safe to use it as return value from calls like CDialog::DoModal() but it is strongly recommended! That type is defined as typedef int __w64 INT_PTR; this means that it is just an int : the __w64 keyword is an hint that the compiler uses to find 64-bit portability issues and warn about it.
|
|
|
|
|
Yes it is! answer to second question is also Yeap
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have a dialog.
I am displaying a messagebox with MB_APPMODAL. It comes over the dialog box (fine till now)
I am having one thread in background which updates dialog and make it top most but if message box is visible then I want messagebox to remain at top. So how to focus on that message box again.
I am using AfxMessageBox to diaplay message.
Well a rough example will like. There are 2 buttons on dialog, 2 messageboxes are already shown. If I click on first button then it will put messagebox1 in foreground , if I click on button 2 then it will put messagebox2 in foreground. I don't want to re-create message box.
I am using AfxMessageBox to diaplay message.
|
|
|
|
|
Your thread could post a user-message at the dialog
and not place the dialog at the top directly...
The dialog message handler function could
1) place the dialog at the top
2) enumerate its children and place all them at the top,
whose class name = _T("#32770") ,
in the enumerating callback function
virtual void BeHappy() = 0;
|
|
|
|
|
Right I was also thinking the same. But my application shows 3 or 4 dialogs so thread might be updating dialog 1 or dialog 2 so I have to put code to handle that message in every dialog which may be at top. Instead of this I wish I could have a handle of that messagebox. If window can have a handle then messagebox should also provide a way to get the handle. Anyways, I am implementing "user-message" solution.
|
|
|
|
|
some tricky ways :- store the caption of your AfxMessageBox() before calling the function. From your other threads, whenever you need to bring message box foreground, call FindWindow('caption'), have message box's handle.. do whatever you want with it.
Try GetLastActivePopup() also, though i haven't used it.
|
|
|
|
|
Couldn't you just use MB_SYSMODAL instead of MB_APPMODAL? Otherwise add MB_TOPMOST?
Good luck!
PURPOSE: Delays program execution until designated condition is indicated.
|
|
|
|
|
Hi,
I want to capture a exception. I used try catch but its not working.Im using the following code. Please suggest me.
LPSTR szError;
try
{
int i = 10;
int j = 0;
int k = i/j;
}
catch(CException *e)
{
e->GetErrorMessage(szError,200,NULL);
}
Thanks,
|
|
|
|
|
The CException *e has somebody to throw. And this wont do the "/" operator.
Use catch(...) what returns GetLastError()
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
its not going to the catch block,after executing the i/j statment,the application is getting crashed.
|
|
|
|
|
I do not think that divide by zero is a catchable exception; try throwing something within your code. Also take a look at this page[^].
It's time for a new signature.
|
|
|
|
|
|
Make at least sure you don't have any optimizing turned on. It might remove your entire code block. Step through the code in the disassembly window, instruction by instruction, and inspect what happens and make sure all the code you expect is there.
|
|
|
|
|
That'll work if you're using managed code as that exception comes from the .NET runtime. However as you originally said you want to catch a CException then you're using MFC which (AFAIK, I may be misinformed) doesn't play nicely with .NET and managed code.
Cheers,
Ash
|
|
|
|
|