Re: Cocoa<->Carbon troubles
Re: Cocoa<->Carbon troubles
- Subject: Re: Cocoa<->Carbon troubles
- From: Frederick Cheung <email@hidden>
- Date: Wed, 21 Jul 2004 22:15:23 +0200
On 21 Jul 2004, at 21:39, Tomas Zahradnicky wrote:
Hello,
Sorry for a pretty long mail but my (still) desperate attempts deserve
some explanation (-:.
I'm in need of WebKit therefore I have to use Cocoa. Not that I did
not like Cocoa (it's truly amazing!!), but I have to use C/C++ for a
plug-in I'm programming and have to do that in CodeWarrior to match
the structure of STL.
The problem I have is that I need to create NSWindow and embed WebView
into it. I created a Cocoa bundle project in Xcode and put a simple
code that creates a window first:
void* WVB_CreateWindow(const Rect *iRect)
{
NSWindow* progress = [[[NSWindow alloc]
initWithContentRect:NSMakeRect(iRect->left,iRect->top,iRect->right-
iRect->left,iRect->bottom-iRect->top) styleMask:NSBorderlessWindowMask
backing:NSBackingStoreRetained defer:NO] autorelease];
[progress setHasShadow:NO];
[progress setOpaque:YES];
[progress makeKeyAndOrderFront:nil];
return progress;
}
and use Carbon code to load that bundle, find WVB_CreateWindow's
function pointer and execute it. The problem is however that the
application plug-in runs in is a Carbon app and therefore no
NSApplication object exists and AppKit is not initialized. The program
ends with:
*** Uncaught exception: <NSInternalInconsistencyException> Error
(1002) creating CGSWindow
If the same code gets executed from a -(void)awakeFromNib method from
a testing cocoa app that calls NSApplicationMain, everything works
normal.
I'd like to get advised on how to:
a) have Cocoa/AppKit initialized (I assume I cannot call
NSApplicationMain(argc,argv) to not let underlying app go mad )
I don't know what AppKit does in its initialization but this
seems that
it estabilishes a connection with WindowServer and creates a raw
window
with CoreGraphics Services API. That would explain why the
buffering
method is required with initWithContentRect method.
b) make this work
c) make this work better (-:
You need to call NSApplicationLoad. You also need to create autorelease
pools whenever you call into Cocoa from Carbon, or you will leak.
Lastly once you've got your autorelease pools, you do not want to
autorelease the window you just created or it will be torn down when
you release your pool.
Fred
Thanks,
Tomas
--
Ing. Tomas Zahradnicky, Jr.
Quality Manager, 24U Software
Associate Member, FileMaker Solutions Alliance
mailto:email@hidden
http://www.24uSoftware.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.