|
palbano wrote:
www.sockets.com
Sadly, none of the links to download examples are live.
Steve S
|
|
|
|
|
Wow, your right! I sent an email. Hopefully it is temporary. That site has been around since 1995 or so. It would be a shame if it disolved.
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
This is exactly what i was looking for
int socket = -1;
//****************************************************************
// ManageSocket
// Call this function every sec
//****************************************************************
void ManageSocket ()
{
fd_set ready;
struct timeval to;
//Check if the connection is active
if (socket > 0 )
{
FD_ZERO(&ready);
FD_SET(socket, &ready);
to.tv_sec = 0;
to.tv_usec = 1;
select(socket + 1, &ready, 0, 0, &to)
if (FD_ISSET(sock, &ready)) //If socket ready
{
//Packet with a size of zero = Connection closed
if ( recv ( sock , buf , 1024 , 0) == 0)
{
//Closing the socket
close(socket);
socket = -1;
}
}
}
// When Connection is inactive client will try to reconnect every sec
else if (Socket < 0)
{
//Reconnect to the host
}
}
|
|
|
|
|
Hi,
I would like to know how to get a pointer to my CView class from CMainFrame class?
Ehsan Behboudi
|
|
|
|
|
See CFrameWnd::GetActiveView().
Cheers,
swine
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
i used it and i got an wierd error,
I had to include my CView header file, in my case it is:
#include "CMotionControllerView.h"
and i got 3 error all had to do with the GetDocument() in CView class !!!!!
Ehsan Behboudi
|
|
|
|
|
You'll probably need to forward declare your CDocument derived class in the CMotionControllerView.h file.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
ok well that doesn't tell me much... you need to be more descriptive if you want help. what exact errors, etc?
perhaps you didn't do the casting correctly...?
[b]yte your digital photos with [ae]phid [p]hotokeeper - www.aephid.com.
|
|
|
|
|
CFrameWnd::GetActiveView() ?
~RaGE();
|
|
|
|
|
It's all in msdn
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Using Visual Studio 2002 and i can't find a "Callers Graph" view like the one that is in VC6. Am i a dope or did they leave it out?
-pete
|
|
|
|
|
it's not called "Callers Graph"!!!
it's called "Call Stack"!!!
have a look at the help files, maybe this term helps...
Don't try it, just do it!
|
|
|
|
|
Thanks Alexander, but it's not the same thing. In VC6 there was both a "Callers Graph" and a "Call Graph" that could be viewed starting from a function. They are not actually graphs but rather a tree control. It was part of the "Browser" functionality. Definitely not the "Call Stack" which is the current running context of course. Quite handy actually, it is very sad if it was left out of VC7 "Browser".
P.S. Are you always that easily exited? All those exclamation characters just seem to fly off your keyboard
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Hi all
I wrote a simple win32 dll (non MFC) and tried to invoke its functions using run-time Loading (LoadLibrary). When I call GetProcAddress() function it returns me always NULL.
I checked in Dependency Walker tool this dll add saw that in some reason to all exported symbols were added some gibrish. for instance: function Foo() is writen like this: ?Foo@@YAHHH@Z. So when i give GetProcAddress() function name it never finds it
strange...
Have any ideas why? and how can i sole this?
b.w.: I'm using VC6 and win XP
thanks.
|
|
|
|
|
Edit your .def-File like this:
EXPORTS
Foo=?Foo@@YAHHH@Z
There must be some option to partially disable name mangling of exported functions, but I can't find it right now :/
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Anonymous wrote:
I wrote a simple win32 dll (non MFC) and tried to invoke its functions using run-time Loading (LoadLibrary).
This does not indicate that two DLLS are being used. I presume this is not the case and that there are actually two DLLS, one MFC and the other non-MFC. Yes?
Are the exported functions written in C++? If so, it sounds like name-mangling is at work here.
|
|
|
|
|
bad answer greg!!!
i assume u defined your function like this:
void __declspec( dllexport ) foo()
{
...
}
this causes c++ name convention when using a c++ compiler!
to get a c export(which u want), use:
extern "C" void __declspec( dllexport ) foo()
{
...
}
Don't try it, just do it!
|
|
|
|
|
10x
Another question: is there any way to use a class defined and exported from a dll loaded by LoadLibrary() ?
Its if you can explain what is a "name convention" it would be grate
thanks.
|
|
|
|
|
i askey myself this question many times, it is possible, the half-life engine does it, but i still dont know how...
Don't try it, just do it!
|
|
|
|
|
Yes there is..
In fact, I pondered over this same problem a while back. The idea was that I was supposed to use a class which is completely declared inside a DLL. I only had the header files for reference.
So, here we go, first the actual class, declared with typedef. Do this in a seperate header file:
[code]
typedef class {
public:
// Some initialization functions ?
virtual HRESULT InitModule(void);
virtual HRESULT QuitModule(void);
// A member variable perhaps ?
int iMemberVariable;
} MyExportedClassType;
// Pointer-to-function returning address-of WindowPlugin class
typedef MyExportedClassType* (*GetClass)(void);
[/code]
What ? A pointer-to-function blablabla ? What's that ?
Simple: That is the key to this whole mess: a pointer to a function. Why is it declared there ? Because the same header file is used in the loading application. Just for the sake of simplicity.
Now, when we have the actual class, let's see the DLL exporting it:
[code]
// On global level, declare an instance of the class
MyExportedClassType MyClass;
// At the DllMain, initialize the class' members
int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpVoid)
{
.... Some code here
MyClass.iMemberVariable = 10;
.... More code here
return TRUE
}
// Add an exported function, which returns the address of our class
__declspec(dllexport) MyExportedClassType* ProvideAddressOfClass(void)
{
return &MyClass;
}
[/code]
Lastly, create a module definition file
[code]
LIBRARY
EXPORTS
ProvideAddressOfClass @1
[/code]
Ok, now the DLL is ready, go compile it. Next up, the loading application:
[code]
// We must include the typedef declaration
#include "myclasstypedef.h"
HDLL hDll;
// See here: let's create a pointer-to-function which returns a class' address.. Remember, we exported this type of function from the DLL !
GetClass MyClassProvider;
// A pointer to our class type
MyExportedClassType* lpImportedClass;
// Your main function
int main(void)
{
.... Some code ?
// Load module
hDll = LoadLibrary(ModuleName[iCount]);
// Resolve address of exported function
MyClassProvider = (GetClass)GetProcAddress(hDLL, "ProvideAddress");
// Get address of class within the DLL, using the exported function
lpImportedClass = MyClassProvider();
// Let's use it !
lpImportedClass->iMemberVariable = 1;
.... Some more code
// Remember to unload the library !
UnloadLibrary(hDll);
// End application
return 0;
}
[/code]
Seems difficult ? Well, it really isn't.. To sum it all up programmer-wise:
1. Create a class using typedef
2. Create a function which returns the address of your class
3. Export this function in the DLL with __declspec AND .def file
4. Create a typedef for 'pointer-to-function' of the address-provider function
5. Load the DLL in another application
6. Get the address of the exported function
7. Use the function to get the address of the class
8. Use the class
9. NULLify pointers, unload the DLL etc clean-up work
10. Quit and get some sleep
I have created an example of this, an application which actually creates it's main window in a seperate DLL, and adds event handlers to this window's procedure in another DLL. You can download the entire workspace (3 projects: WinDLL, InpDLL, WinLoader) from here.
Enjoy !
-Antti
|
|
|
|
|
[EDIT]I'm using VS6[/EDIT]
This is an obscure problem: I'm using an edit control labeled IDC_EDIT2 in a dialog-based app. To restrict the length of the content to 8, I use the following function that is called whenever the content changes:
void CFileCryptDlg::OnChangeEdit2()
{
char strPassword[10];
if(GetDlgItemText(IDC_EDIT2,strPassword,10)>8)
{
strPassword[8]='\0';
SetDlgItemText(IDC_EDIT2,strPassword);
}
}
It works fine, except for one small problem: till I type the 8th character, everything's as expected. But when the 9th character is typed, the cursor moves back to the first location in the edit box. How do I retain the cursor position?
Thanks,
Vikram.
The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.- Dijkstra
KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames.
pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.
|
|
|
|
|
Why don't you just do SendMessage(wndOfYourEdit, EM_EXLIMITTEXT, 8, 0); ?
This will limit the edit control to accept max. 8 chars.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I tried what David said below and it works.
On a purely academic note, how come neither
::SendMessage(((CEdit *)GetDlgItem(IDC_EDIT2))->m_hWnd, EM_EXLIMITTEXT, 8, 0);
nor
GetDlgItem(IDC_EDIT2)->SendMessage(EM_EXLIMITTEXT, 8, 0);
works when called from the dialog's InitInstance() function? They don't restrict the number of characters at all.
Cheers,
Vikram.
The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.- Dijkstra
KI klike KDE kand kuse kit, kbut KI kmust kadmit, kstarting kall knames kwith K kis ksilly. KI khope kthey kwill kgive kup kthis kwhole kscheme ksoon kand kcome kup kwith kreal knames.
pI vThink aHungarian nNotation vIs iA aWonderful nThing cAnd pEveryone avShould vUse pIt aAll dThe nTime, adNo nMatter pWhat dThe nContext, adEven adWhen vSpeaking.
|
|
|
|
|
Probably because a dialog does not have such a method. Are you talking about OnInitDialog() ? Either way, the EM_EXLIMITTEXT message is for rich edit controls.
|
|
|
|
|
Is your edit control already created in InitInstance()? I'd prefer OnInitDialog().
modified 12-Sep-18 21:01pm.
|
|
|
|