ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

acedRegisterFilterWinMsg() and Demand loading

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
453 Views, 2 Replies

acedRegisterFilterWinMsg() and Demand loading

I am sure some of you are beginning to wish I would go away or just shut up,
but I thought I would try one last time to get an answer to this question.

I am having a problem with an application that registers a message filter
via acedRegisterFilterWinMsg(). My application works just fine when I
manually load it, but when I demand load it, my message filter doesn't start
receiving messages right away.

I decided to see if I could duplicate this behavior with a much simpler
program, so I tried it and the stripped down program behaved in the exact
same way. I have attached the small test program I put together to test
this. Basically, it just watches to see if the user presses the F2 key and
prints a notification to the command line. The program's demand load
settings are configured to load it at AutoCAD startup.

For the test I loaded it into AutoCAD so that it could set itself up for
demand loading. Then I closed AutoCAD and fired it back up again. Then I
started pressing the F2 key. My notification message didn't start printing
to the command line until the third key press.

If nobody answers, I promise I won't bring this up again.

Thanks,

Chuck
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

I don't know that this will make any difference, but try moving the
InitApplication call to AcRx::kLoadDwgMsg rather than AcRx::kInitAppMsg.
That will delay the call until the first drawing is fully loaded into
AutoCAD which is essentially the same as when you manually load your app.

"Chuck Gabriel" wrote in message
news:3723974A798213A79C530BEB64096FDB@in.WebX.maYIadrTaRb...
> I am sure some of you are beginning to wish I would go away or just shut
up,
> but I thought I would try one last time to get an answer to this question.
>
> I am having a problem with an application that registers a message filter
> via acedRegisterFilterWinMsg(). My application works just fine when I
> manually load it, but when I demand load it, my message filter doesn't
start
> receiving messages right away.
>
> I decided to see if I could duplicate this behavior with a much simpler
> program, so I tried it and the stripped down program behaved in the exact
> same way. I have attached the small test program I put together to test
> this. Basically, it just watches to see if the user presses the F2 key
and
> prints a notification to the command line. The program's demand load
> settings are configured to load it at AutoCAD startup.
>
> For the test I loaded it into AutoCAD so that it could set itself up for
> demand loading. Then I closed AutoCAD and fired it back up again. Then I
> started pressing the F2 key. My notification message didn't start
printing
> to the command line until the third key press.
>
> If nobody answers, I promise I won't bring this up again.
>
> Thanks,
>
> Chuck
>
>


----------------------------------------------------------------------------
----


// HotKeys.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include

BOOL filterKeys(MSG *pMsg);

HINSTANCE _hdllInstance =NULL ;

// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char*
cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);


// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
void RegisterArxApp();
char ThisAppRegistryPath[] = { "Software\\" };
//}}AFX_ARX_ADDIN_FUNCS


////////////////////////////////////////////////////////////////////////////
//
// Define the sole extension module object.
AC_IMPLEMENT_EXTENSION_MODULE(HotKeysDLL);

// Now you can use the CAcModuleRecourceOverride class in
// your application to switch to the correct resource instance.
// Please see the ObjectARX Documentation for more details

////////////////////////////////////////////////////////////////////////////
/
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID
/*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_hdllInstance = hInstance;
// Extension DLL one time initialization
HotKeysDLL.AttachInstance(hInstance);
InitAcUiDLL();
} else if (dwReason == DLL_PROCESS_DETACH) {
// Terminate the library before destructors are called
HotKeysDLL.DetachInstance();

}
return TRUE; // ok
}



////////////////////////////////////////////////////////////////////////////
/
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
// Comment out the following line if your
// application should be locked into memory
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
InitApplication();
break;
case AcRx::kUnloadAppMsg:
UnloadApplication();
break;
}
return AcRx::kRetOK;
}

// Init this application. Register your
// commands, reactors...
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
RegisterArxApp();
//}}AFX_ARX_INIT

// TODO: add your initialization functions
acedRegisterFilterWinMsg(filterKeys);
}

// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
//}}AFX_ARX_EXIT

// TODO: clean up your application
acedRemoveFilterWinMsg(filterKeys);
}

// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char*
cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
char cmdLocRes[65];

// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {

// Load strings from the string table and register the command.
::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);

} else
// idLocal is -1, so the 'hard coded'
// localized function name is used.
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}

BOOL filterKeys(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_F2))
acutPrintf("\nF2 was pressed.");
return FALSE;
}

// This function registers this ObjectARX Application
// on AutoCAD for demandload and in the
// Windows Registry.
void RegisterArxApp()
{
int strLength;
HMODULE hModule = GetModuleHandle("AsdkHotKeys.arx");

if (!hModule)
return;

//
// Register the application.
//

acrxRegisterApp((AcadApp::LoadReasons) (AcadApp::kOnAutoCADStartup),
"AsdkHotKeys",
ThisAppRegistryPath, 2);

//
// Create the registry key for this application
// (use the variable ThisAppRegistryPath).
//

HKEY rkey;
DWORD result;
LONG status = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
ThisAppRegistryPath,
0, "",
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &rkey, &result);
if (ERROR_SUCCESS != status)
return;

HKEY prodKey;
status = RegCreateKeyEx(rkey, "AsdkHotKeys", 0, "",
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &prodKey, &result);
RegCloseKey(rkey);
if (ERROR_SUCCESS != status)
return;

// Create the 'Loader' key.
HKEY loaderKey;
status = RegCreateKeyEx(prodKey, "Loader", 0, "",
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &loaderKey, &result);
if (ERROR_SUCCESS == status) {
char modulePath[512];
strLength = GetModuleFileName(hModule, modulePath, 512);
if (strLength)
RegSetValueEx(loaderKey, "MODULE", 0, REG_SZ,
(const unsigned char*)modulePath, strLength + 1);
RegCloseKey(loaderKey);
}

// Create the 'Name' key.
HKEY nameKey;
status = RegCreateKeyEx(prodKey, "Name", 0, "",
REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &nameKey, &result);
if (ERROR_SUCCESS == status) {
RegSetValueEx(nameKey, "AsdkHotKeys", 0, REG_SZ,
(const unsigned char*) "AsdkHotKeys", 12);
RegCloseKey(nameKey);
}

//
// Finished.
//

RegCloseKey(prodKey);
}
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks for the suggestion Art. I tried it, but it didn't make any
difference.

I decided to try an experiment to see if I get the same behavior using
SetWindowsHookEx in lieu of acedRegisterFilterWindowsMsg. I just finished
trying it out, and it seems to have eliminated the problem.

Thanks again.

Chuck


"Art Cooney" wrote in message
news:345D3165E34018554A0CA7188D12DB59@in.WebX.maYIadrTaRb...
> I don't know that this will make any difference, but try moving the
> InitApplication call to AcRx::kLoadDwgMsg rather than AcRx::kInitAppMsg.
> That will delay the call until the first drawing is fully loaded into
> AutoCAD which is essentially the same as when you manually load your app.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost