|
I'm new to this, but I have a problem I can't solve, and could do with some help please.
I'm writing an encrypted chat program with VC++ 6, which uses the Winsock API. The encryption is provided by Peter Gutmann's cryptlib library.
The problem is that the encryption process outputs a void pointer to a binary string variable, and sockets as far as I'm aware take a pointer to a character string. The cryptlib documentation suggests using the S/MIME format but I'm not writing an e-mail client/server, I just want to send the data through a socket, something like this:
send( mySocket, encryptedDataBuffer, 1024, 0 );
Is there a way I can convert the binary into a character sequence, send that and then convert it back at the recieving end?
Thanks in advance.
noxon
|
|
|
|
|
Hi noxon
The 2nd argument for the send function is a const char* but remember that send was first written during the old C days and then a byte and a char were the same. This does not mean send can send only null terminated text strings. You can definitely use send to send binary text.The 3rd parameter specifies the number of bytes to send.
Regards,
Nish
"I'm a bit bored at the moment so I'm thinking about writing a new programming language" - Colin Davies
My book :- Summer Love and Some more Cricket [New Win]
Review by Shog9 Click here for review[NW]
|
|
|
|
|
Thanks Nish,
that has cleared up the question of whether I can do it or not. Im glad it was you who answered, it was your tutorial that got me off the ground with Winsock when I started writing the prog.
According to Microsoft void and char pointers are interchangeable without having to cast the pointer. So I'm giving cryptlib a NULL pointer to a character string like so:
char* encryptedDataBuffer = NULL;<br />
<br />
cryptPushData etc...<br />
<br />
cryptPopData( cryptEnvelope, encryptedDataBuffer, encryptedDataBufferSize, &bytesCopied );
But when i then use the code to send it on the Socket:
send( mySocket, encryptedDataBuffer, 1024, 0 );
The program just falls over (crashes), this same function works with a plaitext character string, so if I can send the binary, do you think I need to convert it to a hexadecimal representation of the actual binary, or am I missing something (quite possible).
Many thanks for help.
noxon
|
|
|
|
|
Yes, I know that this is a Visual C++ forum but is there a chance that anyone knows how do I compile a project in unix using gcc or g++ composed in C++ and spread in several .cpp and .h files? To be exact I have nine files the eight of them are pairs .h & .cpp which contains classes and the last one is my main.cpp.
Thanks for any help, Themis
|
|
|
|
|
Themis wrote:
using gcc or g++ composed in C++
At the command prompt type (if the compiler locker isn't already added):
add egcs
then type:
g++ -o ExecutableFileName File1.cpp File2.cpp File3.cpp MainFile.cpp
The -o does not create an object file, this is just an option. The header files should be #include 'ed within their perspective .cpp files. Hope this helps.
-Nick Parker
|
|
|
|
|
You can use gcc to compile individual object (*.o) files from each .cpp file and then you can again use gcc to link these objects files into an executable. But I think you should better construct a "Makefile" and use the gnu utility "make" with it in order to accomplish this job fairly easier. Search for how-to's in google and I'm sure you'll get the answers.
|
|
|
|
|
i m chinese, and i jioned here 5 momth. i like C++, but i m pool in english, wish you can touch me.
|
|
|
|
|
and my msn:
kuhx@msn.com
let us be a friend!
|
|
|
|
|
Hi!
I've got a problem when I use the AfxGetMainWnd function to get a pointer of the main window. I've created a thread to complete some operations, and I want to add an item in a list of my main window (a dialog). Visual C++ crashes. But in the primary thread, I can add an item without crashing.
Can anyone help me????
My code:
UINT MyThread(LPVOID pParam)<br />
{<br />
CGCDlg* Dlg=(CGCDlg*) AfxGetMainWnd ();<br />
ASSERT_KINDOF(CGCDlg, Dlg);<br />
Dlg->m_List.InsertItem (0, "Item");<br />
return 0;<br />
}<br />
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
try to pass this as pParam to your thread-func and cast pParam to CGCDlg* instead of AfxGetMainWnd() .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I doubt it is VC++ crashing, but instead it is your app. AfxGetMainWnd()returns the current threads main window, which isn't what you want.
Try:
AfxGetApp()->GetMainWnd();
There are many restrictions on what you can do with CWnd's in a worker thread, as they aren't in the worker thread's message map.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
|
Hello
While Neville's suggestion is good, the main issue in your case is that you are using a worker thread to access the UI of another thread (a strict NO-NO). Read up on Joseph Newcomer's writings on UI threads or refer MSDN and see how to create a UI thread.
Regards,
Nish
"I'm a bit bored at the moment so I'm thinking about writing a new programming language" - Colin Davies
My book :- Summer Love and Some more Cricket [New Win]
Review by Shog9 Click here for review[NW]
|
|
|
|
|
I highly recommend that you redesign the program such that the worker thread sends a message to main thread for control update.
Kuphryn
|
|
|
|
|
SendMessage() is very dangerous from a worker thread, and can lead to a deadlock. PostMessage() is the safe way to go.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Hi ppl
I created a child windows and I passed the child window handle to a function. And inside that function I used TextOut to print out simply "hallo"
So I simply use
TextOut(hdc, 10, 10, "hallo", 5);
One line is fine, but if I called TextOut like 10 times and incrementing like
TextOut(hdc, 10, 30, "hallo2", 5);<br />
TextOut(hdc, 10, 50, "hallo3", 5);<br />
TextOut(hdc, 10, 70, "hallo4", 5);<br />
.<br />
.<br />
.
Then some of the "hallo"s will be out of the range of the child window and cannot be displayed. So anyone can help me how to make it scrollable?
And another thing is when I resize the child window, like maximizing or minimizing it. The texts will be all gone. So I think that has sth to do with WM_PAINT, right? But how should I make it?
Thanz!!
fRaNkLy i'm FrAnKy
|
|
|
|
|
Oh actually I'm trying to make the application window like a console window, displaying text
So when the text goes on and on, the most recent text will be inside the window's view while the previous ones are scrolled upwards...um...you know what I mean.. hehe
And yes I'm using C to call the windows API using DEV C++ as compiler running on windows XP
So do any of you guyz have any idea on how to make it? Just displaying text on the application window? Thanz!!
fRaNkLy i'm FrAnKy
|
|
|
|
|
This is elementary windows programming. Look up scrollbars in the help. With each line you'll need to set the range of the scroll bar and the position. At some point you'll likely need, and want, to chuck old lines.
There is no magic, just brute force programming.
|
|
|
|
|
Oh but the thing is if I know what I am gonna print, I can use TextOut in the case WM_PAINT. But actually my program is written based on UNIX programming, so I have all those printf and getchar.
And now I simply changed the printf into TextOut. So the TextOut are essentially in the functions that I will call, but not really in the WM_PAINT. That's the tough part for me.
So should I use a buffer or file, and replace all those printf with sth that write into the buffer or file. And then use TextOut to write what is inside the buffer?
Thanz really!!
fRaNkLy i'm FrAnKy
|
|
|
|
|
Use wsprintf and store each line in a CStringArray. You'll need to do this anyway if you want to refresh the screen.
Maintain an index into this array of the top line.
As you write the lines, if the next line will overlap the bottom of the view, you'll need to shift the existing lines up and write the new line where the previous bottom line was. (I suggest precalculating this using GetTextExtent() at start and whenever the view size is changed.)
To scroll the contents up, use CDC::ScrollDC().
(If you're going to have lots of text, you may want to virtualize the above list, though you would still want to buffer up what's actually being displayed.)
|
|
|
|
|
hi,
i want to know how to build a application with multi-language. actually, 3 questions i want to ask...
1) how to change language at run-time (eg. change language btn. trad. chinese, simplified chinese and english by clicking in menu)
2) how to display 2 type of language in same dialog box (eg. button text is traditional chinese, and i can input japanese or simplfied chinese in text box, is it possible?)
3) how can i build a unicode application? where able to find the unicode library? is it the best solution for my situation?
thanks,
jim
|
|
|
|
|
One method is descibed in my article http://www.codeproject.com/cpp/mult_lang_support.asp[^]
If you use the resouce language DLL approach 2) can be achieved by getting the language text from the specific language DLL and explicity setting the text for the relevant control.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
that's impressive! but, i want to know whether it work on button or controls on a dialog?
i tried and found that windows handle menu text and dialog text in different way. when i set the default font as trad. chinese and included simplified chinese in my regional settings. i can see correct text in menu but wrong text in a dialog. when i set simplified chinese as default font, i can see everythings correct.
do u have any more complete information on this aspect?
thanks,
jim
|
|
|
|
|
I can't speak Chinese, ony Polish! Using a resource only DLL means you have to define the menus, dialogs etc. in each language for each resource only DLL. Then when a new resource only DLL is loaded, the Menus Dialogs etc. from the new DLL will be used, rather that the default resources.
But if you just want to use a French text string on and English Dialog box you could do:-
hInstFrench = LoadLibrary(_T("LangFRA.dll"));<br />
LoadString(hInstFrench, ID_TEXT, lpBuffer, nBuffSize);<br />
SetWindowText(hWnd, lpBuffer);
I hope this helps. This is one solution there are many others.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
thanks Ted... let me try your method first! ah! one more question, does it work on win98? or, a win2k without select French, German in regional setting?
thanks,
jim
|
|
|
|