|
hehe. LaoXiang.
I think you can get good advice in CSDN.
<--MFC-->
|
|
|
|
|
Does anyone know how to close a modem connection? The connection was opened by the user, so I don't have a handle to it. But my app needs to hang up the modem when it terminates.
Afterthought:
I guess I need to query the state of the list of RAS connections and hang up the one that's active. Have to go find some RAS code at CP...
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I wrote a function that disconnects the modem:
#include <windows.h>
#include <ras.h>
void HangUp(){
RASCONN *rasc=malloc(1000);
DWORD bs,nc,i,j,dwRet;
RASCONNSTATUS rcs;
MSG msg;
TCHAR s[257];
rcs.dwSize=160;
rasc->dwSize=412;
dwRet=RasEnumConnections(rasc,&bs,&nc);
if(!bs)return;
rasc=realloc(rasc,bs);
if(RasEnumConnections(rasc,&bs,&nc))
return;
for(i=0;i<bs/412;i++){
HRASCONN hrc=rasc[i].hrasconn;
dwRet = RasGetConnectStatus(hrc, &rcs);
if (dwRet != ERROR_INVALID_HANDLE){
RasHangUp(hrc);
while (dwRet != ERROR_INVALID_HANDLE){
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dwRet = RasGetConnectStatus(hrc, &rcs);
}
}
}
free(rasc);
}
Peter O.
|
|
|
|
|
Thanks very much, Peter!
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Sorry for msg below, i forgot to disable HTML.. Anyways, read on...
This function uses RC4's algorithm, but its not working properly. It works on small strings, but not large binarys. I cant find the bug in it.. Its tickin me off! Do you see anything wrong?
Usage;
strcpy(buffer, "This is my test string");
EncryptRC4(buffer, strlen(buffer), "secret", 6);
// buffer is then over-written with the new encrypted string.
// to un-encrypt, just call it again.
EncryptRC4(buffer, strlen(buffer), "secret", 6);
// buffer now holds orginal message.
// using strlen here isnt smart, because NULL character may be generated somewhere in the string buffer, but it fits the demo.
Function;
void EncryptRC4(char *sBuffer, int iBufferLen, char *sKey, int iKeyLen)
{
unsigned char sBox[256], k;
int iOffset, i = 0, j = 0;
for (i = 0; i < 256; i++)
sBox[i] = i;
for (i = 0; i < 256; i++) {
j = (j + sBox[i] + sKey[i % iKeyLen]) % 256;
k = sBox[i];
sBox[i] = sBox[j];
sBox[j] = k;
}
i = 0; j = 0;
for (iOffset = 0; iOffset < iBufferLen; iOffset++) {
i = (i + 1) % 256;
j = (j + sBox[i]) % 256;
k = sBox[i];
sBox[i] = sBox[j];
sBox[j] = k;
sBuffer[iOffset] = sBuffer[iOffset] ^ sBox[(sBox[i] + sBox[j]) % 256];
}
}
|
|
|
|
|
Ok, I'm an idiot! That function works perfectly! I just realized after 2 days of debugging, that the function is perfectly fine... it was that I was using the 'get' member function instead of the 'read' member function of the fstream class.... So i was reading the file in wrong... so it was encrypting the wrong data... LOL ... Blah! Basically the obove function works perfectly for anyone that would like to use it.
|
|
|
|
|
Ok, I simplified it down to just a function instead of a class. This function uses RC4's algorithm, but its not working properly. It works on small strings, but not large binarys. I cant find the bug in it.. Its tickin me off! Do you see anything wrong?
Usage;
strcpy(buffer, "This is my test string");
EncryptRC4(buffer, strlen(buffer), "secret", 6);
// buffer is then over-written with the new encrypted string.
// to un-encrypt, just call it again.
EncryptRC4(buffer, strlen(buffer), "secret", 6);
// buffer now holds orginal message.
// using strlen here isnt smart, because NULL character may be generated somewhere in the string buffer, but it fits the demo.
Function;
void EncryptRC4(char *sBuffer, int iBufferLen, char *sKey, int iKeyLen)
{
unsigned char sBox[256], k;
int iOffset, i = 0, j = 0;
for (i = 0; i < 256; i++)
sBox[i] = i;
for (i = 0; i < 256; i++) {
j = (j + sBox[i] + sKey[i % iKeyLen]) % 256;
k = sBox[i];
sBox[i] = sBox[j];
sBox[j] = k;
}
i = 0; j = 0;
for (iOffset = 0; iOffset < iBufferLen; iOffset++) {
i = (i + 1) % 256;
j = (j + sBox[i]) % 256;
k = sBox[i];
sBox[i] = sBox[j];
sBox[j] = k;
sBuffer[iOffset] = sBuffer[iOffset] ^ sBox[(sBox[i] + sBox[j]) % 256];
}
}
|
|
|
|
|
well ppl!
i have got a real trouble here ,
i am trying to send the 'APPE' (Append) to a FTP server
the other commands like REST or TYPE go well but the data storing or retriving commands give error
WINSOCK error 10038 - socket operaton on non-socket
what to do about it
how to remove it so that i be able to send some data !
PLZZZZZZZZZZ help me
|
|
|
|
|
Hello,
i am somehow new to C programming.
i did a plugin (DLL) written in C and now i need to write an EXE that has to send events to that DLL. I read some articles and i think the best way is to do that with shared memory. There are some articles around with code samples but all use MFC which is not supported in C
Can someone pls provide with me with information how to do that in C? Maybe there is a library that may makes things a bit easier?
Thanks for you help
|
|
|
|
|
Why do you need to send events to that DLL. Why not load it from your exe directly?
Best regards,
Alexandru Savescu
|
|
|
|
|
Your question is a little blurred and i'm not quite sure on what your'e trying to accomplish.
But if you want to share data sections in a DLL then you could do something like this:
#pragma data_seg(".sdata")
int iSharedVar = 0;
#pragma data_seg()
Remember to modify your .DEF file:
SECTIONS
.sdata READ WRITE SHARED
The recommended approach though is using file mappings, this is by the way the underlying technology for the implementation of eg. pipes on Win32. Look up CreateFileMapping and MapViewOfFile in MSDN for details.
"It could have been worse, it could have been ME!" -Rincewind
|
|
|
|
|
thanks for for reply
okay, sorry i try to make it a bit clearer.
The plugin (DLL) is for a program I use (it's not written by me). The DLL is not for EXE i want to write. The EXE is to control the other program (which loads the DLL) via the plugin. Therefore I need IPC because it is 2 different processes.
"Application.exe"
loads DLL <------ "control.exe" sends events to DLL
i hope this helps
|
|
|
|
|
If i understand you correct:
You have written a plugin P, the DLL.
The plugin corresponds to a plugin standard known to the application X that loads P.
You want to send a message to P that will somehow be detected by X.
In that case any of the methods i described are valid, by the way, remember to use some sort of synchronization when using mapped files or shared sections. You could take a look at CreateMutex in MSDN.
Hmm..., I guess i didn't tell you how to set up the loop that checks for the shared data to change, but why spoil all the fun.
But here is a hint: Loop could be set up in DLLMain(), remember to Sleep() sometimes so you won't get exhausted...
You could probably also use som Win32 Event functionality, but I haven't actually got any experience in this, but looking up CreateEvent in MSDN seems like a good idea (just did that and it seems to be what your'e looking for).
"It could have been worse, it could have been ME!" -Rincewind
|
|
|
|
|
Hello,
Can anyone tell me how to convert CString to char*?
Thanks!
|
|
|
|
|
did you try (char *)csMyCString ?
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
It depends - do you want a constant char *? Then doing as Chris said works fine (and usually happens automatically.)
If you want a char * that's not constant, try CString::GetBuffer (and CString::ReleaseBuffer when you're done with the char *.)
Good ol' strcpy to a char array also works.
Even if you win the rat race, you're still a rat.
|
|
|
|
|
If you only need a constant string, you can use the implicit LPCTSTR operator of CString, which under ANSI builds will give you a const char*. If you need a non-constant string, then you can use the GetBuffer() method to get direct access to the underlying buffer, and then ReleaseBuffer() when you have finished with it.
Dave
|
|
|
|
|
You can also do...
(LPTSTR) (LPCTSTR) strYourString
it's a bit dangerous though but can be useful when you need a LPTSTR and know it won't ever be modified.
|
|
|
|
|
Yeah:
1)
CString csTemp = "bla bla";
char *szResult;
szResult = new char[csTemp.GetLength() + 1];
strcpy(szResult,csTemp);
or
csTemp.GetBuffer(0); //This returns char*
|
|
|
|
|
in MSDN there is one example given
Example
The following example demonstrates the use of CString::operator LPCSTR.
// If the prototype of a function is known to the compiler,
// the LPCTSTR cast operator may be invoked implicitly
CString strSports(_T("Hockey is Best!"));
TCHAR sz[1024];
lstrcpy(sz, strSports);
// If the prototype isn't known, or is a va_arg prototype,
// you must invoke the cast operator explicitly. For example,
// the va_arg part of a call to sprintf() needs the cast:
sprintf(sz, "I think that %s!\n", (LPCTSTR) strSports);
// while the format parameter is known to be an LPCTSTR and
// therefore doesn't need the cast:
sprintf(sz, strSports);
// Note that some situations are ambiguous. This line will
// put the address of the strSports object to stdout:
cout << strSports;
// while this line will put the content of the string out:
cout << (LPCTSTR) strSports;
|
|
|
|
|
Hi,
Try GetBuffer methode of CString.
e.g
char *t;
CString str = "teste";
t = str.GetBuffer(10);
|
|
|
|
|
Hello all,
I had a few questions in regards to Dialog windows, and wonder if anybody otu ther knew any of this stuff.
1) I open a dialog window in an MDI, and it ALWAYS is on top of a the MDI Window. I want it to be underneath the MDI window if I click on it.
2) The Dialog windows can be moved outside of the area of the MDI mainframe. I don't want this either. Anybody know how to do that?
Thanks a whole bunch,
NickOne
|
|
|
|
|
NickOne wrote:
I open a dialog window in an MDI, and it ALWAYS is on top of a the MDI Window. I want it to be underneath the MDI window if I click on it.
It cannot be a child of the MDI window then, it will need to be a child of the desktop, or NULL.
NickOne wrote:
The Dialog windows can be moved outside of the area of the MDI mainframe. I don't want this either. Anybody know how to do that?
That's a bit harder - you'll need to handle WM_MOVE ( from memory ) and when it goes outside the MDI area, move it back yourself. It will be a bit ugly ( it will jitter ).
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Put your dialog inside an MDI child.
I don't knows how easy or how hard it is to make it works. You will have to resize the MDI child to fit around the dialog (unless the dialog can itself be resized).
However, I generally do not recommand it since you will have a side effect on command like tile if the dialog is constrained or it can look bad if controls on the dialog are not move appropriatly.
Also, if the MDI client is small (the user can resize it) and the dialog is big, it will be harder to see it...
If neither of these potential problems affect you, then go ahead and try it... I know it was possible with Borland and OWL but I don't knows with MFC since we now avoid MDI child dialogs and I do less UI since I uses VC...
Philippe Mori
|
|
|
|
|
NickOne wrote:
1)
NickOne wrote:
2)
You should be able to accomplish both of these, at least in part, by creating your dialog as a child of the MDI client window. You will, however, have to add code if you wish to make it act like a normal MDI child (bring to front on mouse click, get cycled through by CTRL+TAB, highlight the title bar when active). You could get around this if you're using MFC by using a CFormView instead of a CDialog, and just modify the window style to give it a dialog border.
Shog9
--
Maybe Java is kind of like God, it "works in mysterious ways". It seems like your apps are running slowly, because in the backgroud Java is solving world hunger, or finding the cure to cancer.
- Ryan Johnston, Don't die java!
|
|
|
|
|