|
ok, i see that makes it all clear. In a related question, when i have multiple threads and when i do a WSASendTo or whatever, it returns -1 so i use WSAGetLastError(). to retrieve the error. Does WSAGetLastError() returns the last error associated with that specific thread, or could it happen that 2 threads at the same time store an error and that i might retrieve an error from another thread with WSAGetLastError()? ( doest seems likely but who knows)
|
|
|
|
|
Yes WSAGetLastError() returns the error code for the last socket API called on the calling thread.
Mark
|
|
|
|
|
And....especially for overlapped calls, you should check the error EVERY time the API indicates
an error. Otherwise there's no way to effectively manage the overlapped buffers.
Mark
|
|
|
|
|
ok, thnx
|
|
|
|
|
Hi,
Knowing that it is possible to instantiate a new object at runtime with CRuntime class, I was wondering if it would be possible to allow a user of an application to create a new variable at runtime.
For example the user inputs the name of the variable from within an edit control and selects the type of the variable from a ComboBox.
Finaly the new variables and their values could be saved when the user exits the application.
Is there a possibility to do it? If yes could you please tell me how to do it or where I can get further documentation?
With many for your help.
|
|
|
|
|
If MFC...
Check out the CArchive class. If you implement the classes as serializable then you can save and
create from saved objects of the classes.
Serialization in MFC[^]
|
|
|
|
|
you cannot do this in C++.
BUT
You could create a map containing the name of the variable and a pointer to a user defined type :
for example in very pseudo-c++code :
class MyTypes
{
};
class MyIntType : public MyTypes
{
int m_iValue;
}
class MyVariable
{
MyType* m_pType;
std::string m_sVariableName;
}
std::map< std::string, MyVariable* > myVariableMap;
MyIntType myValue = new MyIntType( 123 );
myVariableMap.insert( "myIntVariable", new MyVariable( "myIntVariable", myValue ));
And then when lookup in the map to find the variable ( by name ).
I'm sure you could add a template somewhere in there, as well as operators on MyVariable to manage your series of custom types.
|
|
|
|
|
Arris7 wrote: For example the user inputs the name of the variable from within an edit control and selects the type of the variable from a ComboBox.
This is not possible in c++.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Hi there,
I need to add the code in C++ to an sim card reader application.
I will add a button into existing application but I need the code that will save sim card numbers as text file.
Many thanks,
Regards
Tonny
|
|
|
|
|
I used to use the function to try and determine if a program was running as a system service (versus a userland program)... It seems to have fallen of the face of the earth.
I have a work around (GetTokenInformmation wich requires a user defined buffer), but I'm suprised at how it just disappeared.
Even Richter and Clark discuses it in their book Programming Server-Side Applications for Microsoft Windows 2000[^]
Jeff
BOOL bResult = FALSE;
SID_IDENTIFIER_AUTHORITY siaAuthority = SECURITY_NT_AUTHORITY;
PSID psidLocalSystem = NULL;
HANDLE hToken = INVALID_HANDLE_VALUE;
VOID* lpTokenInformation = NULL;
TOKEN_USER* lpUserToken = NULL;
__try {
if( FALSE == AllocateAndInitializeSid( &siaAuthority,
1, SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0, &psidLocalSystem ) )
{ __leave; }
if( FALSE == IsValidSid( psidLocalSystem ) ) { __leave; }
if( FALSE == OpenProcessToken( GetCurrentProcess(),
TOKEN_QUERY | TOKEN_QUERY_SOURCE, &hToken ) )
{ __leave; }
if( INVALID_HANDLE_VALUE == hToken )
{ __leave; }
DWORD dwNeeded = 0;
GetTokenInformation( hToken, TokenUser, NULL, 0, &dwNeeded );
if( 0 == dwNeeded ) { __leave; }
lpTokenInformation = HeapAlloc( GetProcessHeap(), 0, dwNeeded );
if( NULL == lpTokenInformation ) { __leave; }
assert( dwNeeded < 0x7FFF8 );
DWORD dwSize = dwNeeded;
if( FALSE == GetTokenInformation( hToken,
TokenUser, lpTokenInformation, dwSize, &dwNeeded ) )
{ __leave; }
lpUserToken = static_cast<TOKEN_USER*>( lpTokenInformation );
if( FALSE == IsValidSid( lpUserToken->User.Sid ) ) { __leave; }
if( TRUE == EqualSid( psidLocalSystem, lpUserToken->User.Sid ) )
{ bResult = TRUE; }
}
__finally { }
if( NULL != psidLocalSystem )
{ FreeSid( psidLocalSystem ); }
if( NULL != hToken )
{ CloseHandle( hToken ); }
if( NULL != lpTokenInformation )
{ HeapFree( GetProcessHeap(), 0, lpTokenInformation ); }
return bResult;
|
|
|
|
|
Sounds like it was example code.
GetTokenInformation() follows the "standard" convention of call once to get the required buffer
size then call again to get the buffer.
Mark
|
|
|
|
|
Without going in details, I have an embedded browser which allows limited web usage by customers. It uses IE6, fully patched with no ActiveX control or Java. It does not allow any downloads and destroys any child windows as soon as it sees them (it's the only way I found to block the file open/save dialogs in Yahoo's mail attachment feature.) Since most web sites now use JavaScript, it does allow that.
Does anyone know of any other exploits to watch out for (aside from the buffer overruns or hacks that take advantage of IE6 bugs)? I don't know JavaScript beyond the very basics. Are there things you can do with it that I'm not aware of? (Like the Yahoo! being able to open files.)
-- modified at 13:05 Monday 15th January, 2007
Please, DO NOT suggest alternate ways to do the embedded browser. What I've listed are the requirements and they aren't going to change. Neither are we adding a bunch of code to filter the contents of the web pages; we have a proxy already doing some of that. The ONLY issue is whether there are things you can do in JavaScript to compromise a system or allow a system to be compromised that I'm not aware of.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi Joe,
Two things com to mind. I'm not sure if one applies.
One:
Use IE in KIOSK mode. This is simply general hardening.
Two:
Use MarkupServices and HTMLDocument to interrogate scripting behavior before it occurs (you may be able to squash anything you don't explicitly allow through this route).
My iPAQ is dead, so I can't test either one for you...
Jeff
|
|
|
|
|
KIOSK mode is pretty lame and doesn't allow us to do what we want. Moreover, it doesn't block hot keys.
Jeffrey Walton wrote: Use MarkupServices and HTMLDocument to interrogate scripting behavior before it occurs (you may be able to squash anything you don't explicitly allow through this route).
Not practical since it assumes we know what to look for. It also makes this feature more complicated than it needs to be.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Probably not of much help, but here goes
This might be out of the realm of answers your looking for but, there are a number of system policies that can be set to control IE. Link to Administrators kit Download Internet Explorer Administration Kit 6 Service Pack 1[^]
What I’m not clear about is if you want to protect the system from Java / VB Scripting? If that’s the case I wonder if Shog or David Stone hang out in one of the web dev boards. I bet they would have a good idea of what JS to stop.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
I've got a shiny new PDA I'm trying to play with. I've downloaded the trial of VS2005 & the mobile sdk from microsoft site.
I'm trying to get started, but I can't get the new-mfc-mobile wizard to make me a blank probject.
Does anyone have a "hello world" project they can mail me? or can spend 30s making a blank project?
I don't need any actual code, other than a place holder saying "type stuff here...."
Either reply to this (email or post), or email a project to iain.clarke@ gmail dot com.
Thanks in advance,
Iain.
|
|
|
|
|
Iain Clarke wrote: I'm trying to get started, but I can't get the new-mfc-mobile wizard to make me a blank probject.
Are you receiving an error?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
To attempt to make a project, I go File->New->Project
That pops up a New Project dialog (shock!)
I pick Visual C++, Smart Device, MFC Smart Device Application.
I give it a name in the bottom fields, and press OK.
The dialog goes away, the main window flashes a bit, and a get a few brief hourglasses.
About 3s later, the New Project dialog comes back...
So, no error, but wrong behaviour.
I already have VC6 installed, so there may be path collisions. As my main work is developed in VC6, I'm not quite prepared to vape my system and just have vx2005 on it...
Any help / hints you can give will be appreciated!
Iain.
|
|
|
|
|
|
Iain Clarke wrote: The dialog goes away, the main window flashes a bit, and a get a few brief hourglasses.
About 3s later, the New Project dialog comes back...
So, no error, but wrong behaviour.
It's not wrong behavior. It means that eVC++ is not able to detect your embedded device connected to your computer. To start a new project, build and deploy/debug it successfully, you need to have your embedded device connected to your computer.
Install ActiveSync, and also install the SDK that came along with your embedded device. By all means I am assuming that your embedded device is running some version of WindowsCE.
Connect your device, let ActiveSync detect it and then open eMbedded Visual C++ and then try starting a new project.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
That sounds like a very good explanation - I just wish it popped up a failure explanation, rather than just coming back.
I've tried it, and its not working yet. I'll find a virgin PC somewhere to reinstall from scratch and try your theory out - but this time with the mobile device plugged in the whole time.
Iain.
|
|
|
|
|
Iain Clarke wrote: I've tried it, and its not working yet.
This thing happened to me too at the beginning. It might be that the version of WinCE running on the handheld is not compatible with your eVC++. If you have VS2K3 installed, then just try a new smart device project (with C#) and if it might work. In this case, you can be sure about the uncompatibility factor.
Also get the service pack[^] installed.
-- modified at 4:43 Tuesday 16th January, 2007
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
I'm using VS2005 with the windows mobile 5.0 sdk as recommended on the microsoft website.
That said, it wouldn't be the first time they're wrong. I'll try to get a copy of eVC4 later and download that. It may be simpler and work more easily! (I hope...)
Iain.
|
|
|
|
|
Is there any way to create a DLL that uses SDI/MDI architecture independenly from the main project (caller of the DLL)?
Is there any simple example with source code that a main applcation calls a simple DLL that loads the its own main frame window?
Regards,
sdancer75
|
|
|
|
|
I have taken a stab at creating my own high-res timer class. It works by launching a thread which queries the high performance counter and calls a callback when when the event is triggered. The trouble is it uses a lot of the CPU's idle time when looping. The full thread callback follows, I wonder if anybody could suggest a way to decrease the CPU usage.
UINT CTimer::ThreadProc( LPVOID pParam )
{
LPTIMERDATA tData = (LPTIMERDATA)pParam;
EnterCriticalSection( &m_csLock );
LARGE_INTEGER lilastTime = m_liStartTime;
UINT_PTR uIdEvent = tData->uIdEvent;
UINT uSleepTime = tData->uSleepTime;
HWND hWnd = tData->hWnd;
LeaveCriticalSection( &m_csLock );
LARGE_INTEGER liCurrentTime;
BOOL bIsActive = TRUE;
do
{
QueryPerformanceCounter( &liCurrentTime );
double dMilliSecs = ( (double)liCurrentTime.QuadPart - (double)lilastTime.QuadPart );
dMilliSecs /= (double)m_liFrequency.QuadPart;
dMilliSecs *= 1000;
if ( (UINT)dMilliSecs % uSleepTime == 0 )
TimerProc( hWnd, WM_TIMER, uIdEvent, GetTickCount() );
EnterCriticalSection( &m_csLock );
uSleepTime = tData->uSleepTime;
bIsActive = tData->bIsRunning;
LeaveCriticalSection( &m_csLock );
Sleep(0);
} while( bIsActive );
_endthreadex( 1 );
return 0;
}
Also I test for the even using if ( (UINT)dMilliSecs % uSleepTime == 0 ) I'm worried this would miss a beat.
|
|
|
|