Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

The example "Shapes" c-hook


Recommended Posts

Hi All,

 

I'm just starting on c-hooks for MasterCAM. I tried to copy & implement the SHAPES example and have followed all the steps, including VC++ project settings, and have referred to previous threads on this topic.

I'm still not able to figure out how to get rid of the following errors:

 

--------------------Configuration: Shapes - Win32 Debug--------------------

Linking...

mfcs42d.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already defined in Shapes.obj

mfcs42d.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already defined in Shapes.obj; second definition ignored

Creating library Debug/Shapes.lib and object Debug/Shapes.exp

Debug/Shapes.dll : fatal error LNK1169: one or more multiply defined symbols found

Error executing link.exe.

 

Shapes.dll - 2 error(s), 1 warning(s)

 

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

 

Can anyone help solve this problem?

 

Thanks very much!

Link to comment
Share on other sites

I'm not sure how to use the code tag, but hope this works. I think I copied the content of the Shapes.cpp file 'as is' from the given example code. So, I'll insert only the start and the end of the code here.

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

code:

// Shapes.cpp : Defines the initialization

//

#include "stdafx.h"

#include <math.h>

#undef EXPORT

 

extern "C"

{

#include "m_vars.h"

#include "m_math.h"

#include "m_menu.h"

#include "m_graph.h"

#include "m_io.h"

#include "m_db.h"

#include "m_chain.h"

#include "m_undo.h"

#include "m_ncvars.h"

#include "m_nc.h"

#include "m_init.h"

 

void __declspec(dllexport) m_main(long *ptrs);

}

 

#include "shapes.h"

#include "shapedlg.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

 

BEGIN_MESSAGE_MAP(CShapesApp, CWinApp)

//{{AFX_MSG_MAP(CShapesApp)

// NOTE - the ClassWizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks of generated code!

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

///////////////////////////////////////////////

// CShapesApp construction

 

CShapesApp::CShapesApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

}

 

///////////////////////////////////////////

// The one and only CShapesApp object

 

CShapesApp theApp;

 

// compute unit length axis vectors from an angle

 

static void compute_axis_vectors (

real angle, // I: angle defining the x axis

p_2d v_x, // O: x unit vector

p_2d v_y) // O: y unit vector

 

{

vec (cos (angle), sin(angle), v_x);

vec (-v_x[Y], v_x[X], v_y);

}

 

and so on...

 

// Purpose: main function

 

static void chook_main (void)

 

{

boolean show_dialog;

short f_key;

Cshapedlg dlg;

 

// Enable use of the MFC dynamically linked libraries

 

AFX_MANAGE_STATE( AfxGetStaticModuleState() );

 

show_dialog = TRUE;

undo_hold();

while (TRUE)

{

if (show_dialog)

{

if (dlg.DoModal() == IDOK) // run the dialog

create_shape (dlg.m_create_n, dlg.m_shape_n,

dlg.m_width, dlg.m_height, dlg.m_angle * D2R,

dlg.m_create_point);

else // Cancel

break;

}

cleartextall();

menu (TEXT_HDR, MENU_1); // Display the Option / Create menu

f_command (&f_key, 1); // Get user's selection

if (f_key != 1)

break;

}

}

 

// Purpose: Entry point for C-Hooks programs

 

extern "C" void CH_ENTRY m_main (long *ptrs)

{

if (open_app (ptrs))

chook_main();

close_app (ptrs);

}

 


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

 

While I was pasting this code for you, I was also trying to rebuild Shapes.dll, and it worked. I don't know how that happened. Anyway, I now get an error --

"Debug Assertion failed"

File: afxwin1.inl, line 22

when I try to run the debug version of Shapes.dll in MasterCAM. And ofcourse, I get many linker errors when trying to build a release version.

 

PLease let me know if any of this makes sense to you. Thank you, I appreciate your help.

Link to comment
Share on other sites

Ok, let's be certain of a few things...

 

Are you using MSVC6.0 or a .NET version?

 

Did you create your C-Hook project with the MF App Wizard (Dll)?

 

Let's just worry about the Release build for now (distrubting debug version of the MFC and VCRT DLLs isn't fun). Do your Project Settings look similar to this (MSVC6.0)?

 

chook_projectsettings_generaltab.gif

chook_projectsettings_generaltab_general.gif

Warning level 4 is just a habit of mine, so the default of 3 is fine.

chook_projectsettings_generaltab_codegen.gif

chook_projectsettings_generaltab_preprocessor.gif

I use this for preprocessor defs:

code:

WIN32,NDEBUG,_WINDOWS,_WINDLL,_AFXDLL,_MBCS,_USRDLL,_MSVC_,MSWINDOWS

Your path to the SDK will be different, obviously.

Link to comment
Share on other sites

Using MSVC++ 6.0

 

Created a single project with the MFC AppWizard DLL (as an extension DLL though ). I have commented out the code that comes with the "extension DLL".

 

My project settings look similar, except that I had _AFXEXT added to preprocessor defs. I got rid of that and tried to rebuild release DLL and got similar results (29 errors).

 

[if I choose to ignore the "Debug Assertion failed" error in MasterCAM, the Shapes dialog box does pop up and I can create shapes]

Link to comment
Share on other sites

I commented out the following code

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

code:

  

 

/*

static AFX_EXTENSION_MODULE ShapesDLL = { NULL, NULL };

 

extern "C" int APIENTRY

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)

{

// Remove this if you use lpReserved

UNREFERENCED_PARAMETER(lpReserved);

 

if (dwReason == DLL_PROCESS_ATTACH)

{

TRACE0("SHAPES.DLL Initializing!n");

 

// Extension DLL one-time initialization

if (!AfxInitExtensionModule(ShapesDLL, hInstance))

return 0;

 

// Insert this DLL into the resource chain

// NOTE: If this Extension DLL is being implicitly linked to by

// an MFC Regular DLL (such as an ActiveX Control)

// instead of an MFC application, then you will want to

// remove this line from DllMain and put it in a separate

// function exported from this Extension DLL. The Regular DLL

// that uses this Extension DLL should then explicitly call that

// function to initialize this Extension DLL. Otherwise,

// the CDynLinkLibrary object will not be attached to the

// Regular DLL's resource chain, and serious problems will

// result.

 

new CDynLinkLibrary(ShapesDLL);

}

else if (dwReason == DLL_PROCESS_DETACH)

{

TRACE0("SHAPES.DLL Terminating!n");

// Terminate the library before destructors are called

AfxTermExtensionModule(ShapesDLL);

}

return 1; // ok

}

*/

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

And added this code mentioned in the Shapes.cpp example:

 

code:

  

 

 

// Note!

//

// If this DLL is dynamically linked against the MFC

// DLLs, any functions exported from this DLL which

// call into MFC must have the AFX_MANAGE_STATE macro

// added at the very beginning of the function.

//

// For example:

//

// extern "C" BOOL PASCAL EXPORT ExportedFunction()

// {

// AFX_MANAGE_STATE(AfxGetStaticModuleState());

// // normal function body here

// }

//

// It is very important that this macro appear in each

// function, prior to any calls into MFC. This means that

// it must appear as the first statement within the

// function, even before any object variable declarations

// as their constructors may generate calls into the MFC

// DLL.

//

// Please see MFC Technical Notes 33 and 58 for additional

// details.

//

 

/////////////////////////////////////////////////////////////////////////////

// CShapesApp

 

BEGIN_MESSAGE_MAP(CShapesApp, CWinApp)

//{{AFX_MSG_MAP(CShapesApp)

// NOTE - the ClassWizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks of generated code!

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

/////////////////////////////////////////////////////////////////////////////

// CShapesApp construction

 

CShapesApp::CShapesApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

}

 

/////////////////////////////////////////////////////////////////////////////

// The one and only CShapesApp object

 

CShapesApp theApp;

Link to comment
Share on other sites

I commented out the following code

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

code:

  

 

/*

static AFX_EXTENSION_MODULE ShapesDLL = { NULL, NULL };

 

extern "C" int APIENTRY

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)

{

// Remove this if you use lpReserved

UNREFERENCED_PARAMETER(lpReserved);

 

if (dwReason == DLL_PROCESS_ATTACH)

{

TRACE0("SHAPES.DLL Initializing!n");

 

// Extension DLL one-time initialization

if (!AfxInitExtensionModule(ShapesDLL, hInstance))

return 0;

 

// Insert this DLL into the resource chain

// NOTE: If this Extension DLL is being implicitly linked to by

// an MFC Regular DLL (such as an ActiveX Control)

// instead of an MFC application, then you will want to

// remove this line from DllMain and put it in a separate

// function exported from this Extension DLL. The Regular DLL

// that uses this Extension DLL should then explicitly call that

// function to initialize this Extension DLL. Otherwise,

// the CDynLinkLibrary object will not be attached to the

// Regular DLL's resource chain, and serious problems will

// result.

 

new CDynLinkLibrary(ShapesDLL);

}

else if (dwReason == DLL_PROCESS_DETACH)

{

TRACE0("SHAPES.DLL Terminating!n");

// Terminate the library before destructors are called

AfxTermExtensionModule(ShapesDLL);

}

return 1; // ok

}

*/

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

And added this code mentioned in the Shapes.cpp example:

 

code:

  

 

 

// Note!

//

// If this DLL is dynamically linked against the MFC

// DLLs, any functions exported from this DLL which

// call into MFC must have the AFX_MANAGE_STATE macro

// added at the very beginning of the function.

//

// For example:

//

// extern "C" BOOL PASCAL EXPORT ExportedFunction()

// {

// AFX_MANAGE_STATE(AfxGetStaticModuleState());

// // normal function body here

// }

//

// It is very important that this macro appear in each

// function, prior to any calls into MFC. This means that

// it must appear as the first statement within the

// function, even before any object variable declarations

// as their constructors may generate calls into the MFC

// DLL.

//

// Please see MFC Technical Notes 33 and 58 for additional

// details.

//

 

/////////////////////////////////////////////////////////////////////////////

// CShapesApp

 

BEGIN_MESSAGE_MAP(CShapesApp, CWinApp)

//{{AFX_MSG_MAP(CShapesApp)

// NOTE - the ClassWizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks of generated code!

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

/////////////////////////////////////////////////////////////////////////////

// CShapesApp construction

 

CShapesApp::CShapesApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

}

 

/////////////////////////////////////////////////////////////////////////////

// The one and only CShapesApp object

 

CShapesApp theApp;

Link to comment
Share on other sites

quote:

Created a single project with the MFC AppWizard DLL (as an extension DLL though ). I have commented out the code that comes with the "extension DLL".


I would allow the MFC App Wizard (DLL) to create a regular DLL that uses the shared MFC DLLs.

 

quote:

I commented out the following code

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

code:

  

 

/*

static AFX_EXTENSION_MODULE ShapesDLL = { NULL, NULL };

 

extern "C" int APIENTRY

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)

{

// Remove this if you use lpReserved

UNREFERENCED_PARAMETER(lpReserved);

 

if (dwReason == DLL_PROCESS_ATTACH)

{

TRACE0("SHAPES.DLL Initializing!n");

 

// Extension DLL one-time initialization

if (!AfxInitExtensionModule(ShapesDLL, hInstance))

return 0;

 

// Insert this DLL into the resource chain

// NOTE: If this Extension DLL is being implicitly linked to by

// an MFC Regular DLL (such as an ActiveX Control)

// instead of an MFC application, then you will want to

// remove this line from DllMain and put it in a separate

// function exported from this Extension DLL. The Regular DLL

// that uses this Extension DLL should then explicitly call that

// function to initialize this Extension DLL. Otherwise,

// the CDynLinkLibrary object will not be attached to the

// Regular DLL's resource chain, and serious problems will

// result.

 

new CDynLinkLibrary(ShapesDLL);

}

else if (dwReason == DLL_PROCESS_DETACH)

{

TRACE0("SHAPES.DLL Terminating!n");

// Terminate the library before destructors are called

AfxTermExtensionModule(ShapesDLL);

}

return 1; // ok

}

*/


Right. This code is generated when creating an extension DLL. C-Hooks aren't MFC extensions. The main class for the C-Hook isn't generated, either (something that the App Wizard will do with regular DLLs).
Link to comment
Share on other sites

I was finally able to make a release DLL version without any errors or warnings. I had ignored a few libraries (MSVCRT, mfcs42d.lib) in the project settings while debugging the code. I got rid of that, and everything is working fine now.

 

Thanks for your help.

 

MRB.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...