# Creating a toolbar through C-API

This topic is 3674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I made a dll that has a bunch of function. One of them creates a CFrameWnd window. Inside the function that creates my CFrameWnd, I can create a CToolBar object. However I now want the user of the dll to be able to attach a customized CToolBar object to that window (instead of the default CToolBar object that I created during window creation). So I thought I simply create the customized CToolBar object in the client application in the same way I did in the dll function. That however does not seem to work: in release mode the toolbar appears, but doesn't have any bitmap, in debug mode, I get a debug assertion error in following function of "afxwin1.inl":
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{ ASSERT(afxCurrentInstanceHandle != NULL);
return afxCurrentInstanceHandle; }


my toolbar is created (or rather I attempt to create my toolbar) in the client application with:
	CToolBar* toolBar;
toolBar=new CToolBar();
toolBar->CreateEx((CFrameWnd*)dllFunctionGetFrameWnd(),TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_SIZE_DYNAMIC|CBRS_TOP|WS_CLIPCHILDREN|WS_CLIPSIBLINGS);


What can I possibly be doing wrong?

##### Share on other sites
What could you possibly be doing wrong?

Um, Going with MFC? [grin] Have you searched Joseph Newcomer's site for solutions? What about CodeProject?

##### Share on other sites
Thank you LessBread. I had a look at CodeProject and might have found where my problem lies. I cannot test it right now but the mistake I could have done is that at the beginning of each exported dll function, I call following function:
void commonDllStartRoutine(){	AFX_MANAGE_STATE(AfxGetStaticModuleState());}

I didn't realize that the macro AFX_MANAGE_STATE would loose its effect at the end of its scope! (so my calls to commonDllStartRoutine() don't have any effect it seems!)

Might that be my problem?

1. 1
2. 2
JoeJ
20
3. 3
frob
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632210
• Total Posts
3004791

×