using type libraries and shared lib under vba

J

jjaeger

Hello,

I have set up some tool in C++ under Windows that I have ported to Mac OS
X.

I have problems to use the code under Excel 11.1.1 .

Under windows I created xxx.dll and xxx.tlb. I used the reference menu to
integrate these type libraries into vba.

Under Mac I created libxxx.dylib files and tried to reuse the xxx.tlb
compiled under windows.

The compile is OK, but when I run the vba, the error xxx.dll not found is
raised.

What should I do?

I tried rename libxxx.dylib to xxx.dll under Mac.

Is there a mktyplib.exe for Mac ?

Thanks in advance for your help

Jurgen
 
J

Jean-Claude Arbaut

Hello,

I have set up some tool in C++ under Windows that I have ported to Mac OS
X.

I have problems to use the code under Excel 11.1.1 .

Under windows I created xxx.dll and xxx.tlb. I used the reference menu to
integrate these type libraries into vba.

Under Mac I created libxxx.dylib files and tried to reuse the xxx.tlb
compiled under windows.

The compile is OK, but when I run the vba, the error xxx.dll not found is
raised.

What should I do?

I tried rename libxxx.dylib to xxx.dll under Mac.

Is there a mktyplib.exe for Mac ?

Thanks in advance for your help

Jurgen

Usually a dylib is linked to an executable at compile time, I think you
should try to compile a "bundle", that's a better equivalent of DLL.
Another issue: I'm not sure Excel is able to load Mach-O files. If you look
at "Solver Library" for example, it's a PEF file.
 
J

jjaeger

Are there any example on the net how to use c++ using typelib or .bundle
or .dylib with mac Excel ?
 
J

jjaeger

Hello,

I have set up some tool in C++ under Windows that I have ported to Mac OS
X.

I have problems to use the code under Excel 11.1.1 .

Under windows I created xxx.dll and xxx.tlb. I used the reference menu to
integrate these type libraries into vba.

Under Mac I created libxxx.dylib files and tried to reuse the xxx.tlb
compiled under windows.

The compile is OK, but when I run the vba, the error xxx.dll not found is
raised.

What should I do?

I tried rename libxxx.dylib to xxx.dll under Mac.

Is there a mktyplib.exe for Mac ?

Thanks in advance for your help

Jurgen

Usually a dylib is linked to an executable at compile time, I think you
should try to compile a "bundle", that's a better equivalent of DLL.
Another issue: I'm not sure Excel is able to load Mach-O files. If you
look
at "Solver Library" for example, it's a PEF file.

Thanks for your answer,

I tried bundle file, but it does not solve the problem.

I did see in the helpsection of the declare statement und vba for
applications mac, that they deal with shared libraries, I thought they are
talking about .dylib files.

The Mach-O file, does it correspond to the static link option in the Xcode
tool.

Which application type does correspond to this under Xcode 1.5 : BSD
application, shell tool, shared lib?
 
J

Jean-Claude Arbaut

Usually a dylib is linked to an executable at compile time, I think you
should try to compile a "bundle", that's a better equivalent of DLL.
Another issue: I'm not sure Excel is able to load Mach-O files. If you
look
at "Solver Library" for example, it's a PEF file.

Thanks for your answer,

I tried bundle file, but it does not solve the problem.

I did see in the helpsection of the declare statement und vba for
applications mac, that they deal with shared libraries, I thought they are
talking about .dylib files.

The Mach-O file, does it correspond to the static link option in the Xcode
tool.

Which application type does correspond to this under Xcode 1.5 : BSD
application, shell tool, shared lib?


I looked at Excel help, and it seems to me that they are talking about PEF
files ("code fragment" and "resource" usually refer to Apple CFM and old
binary format).

Little explanation: MacOS 9 used double-fork files for programs as well as
"user" files, to store data and resources in the same file (hence the "data
fork" and the "resource fork"). When you read first bytes of the data fork
of an executable file, you get "Joy!peffpwpc". And These are PEF files.

OSX has completely changed this, and uses Mach-O binary files (and files
don't use 2 forks anymore - it's supported, but discouraged).
If you look closely at an Apple application, it's a folder: you can open it
with right-click and "Show Package Contents". Inside this folder, you'll
find usuall an executable file in the Mach-O format, and resource files (and
sometimes libraries, etc...). And when you read first bytes, you get "fe ed
fa ce" in hex dump.

OSX has still support for CFM (Code Fragment Manager) applications. Indeed,
many carbon applications can run under both OS9 ans OSX. But XCode can only
compile Mach-O, for one simple reason: it uses gcc as a compiler, an gcc
(under OSX) can only produce Mach-O executables.

I looked at several files of Office, and they are all PEF files (including
the Excel program). And if you look at folder /System/Library/CFMSupport/,
you should find CarbonLib and StdCLib (among others), put there when you
installed Office. So I think I can conclude Office is a carbon application,
using the old CFM "model". But note Carbon applications can also be compiled
in Mach-O apps, it's just a design choice. And I am almost certain you will
need to compile CFM dynamic libs to be able to load them in Excel.
As I said above, XCode cannot do that. I suppose CodeWarrior can. And MPW
under OS9 certainly can.

If you have only OSX, Xcode and Office, I fear it's bad luck ;-)
But if you find a solution, I am interested ! I would be very happy to
compile dylibs for Excel...
 
J

jjaeger

Usually a dylib is linked to an executable at compile time, I think you
should try to compile a "bundle", that's a better equivalent of DLL.
Another issue: I'm not sure Excel is able to load Mach-O files. If you
look
at "Solver Library" for example, it's a PEF file.

Thanks for your answer,

I tried bundle file, but it does not solve the problem.

I did see in the helpsection of the declare statement und vba for
applications mac, that they deal with shared libraries, I thought they are
talking about .dylib files.

The Mach-O file, does it correspond to the static link option in the Xcode
tool.

Which application type does correspond to this under Xcode 1.5 : BSD
application, shell tool, shared lib?


I looked at Excel help, and it seems to me that they are talking about PEF
files ("code fragment" and "resource" usually refer to Apple CFM and old
binary format).

Little explanation: MacOS 9 used double-fork files for programs as well as
"user" files, to store data and resources in the same file (hence the
"data
fork" and the "resource fork"). When you read first bytes of the data fork
of an executable file, you get "Joy!peffpwpc". And These are PEF files.

OSX has completely changed this, and uses Mach-O binary files (and files
don't use 2 forks anymore - it's supported, but discouraged).
If you look closely at an Apple application, it's a folder: you can open
it
with right-click and "Show Package Contents". Inside this folder, you'll
find usuall an executable file in the Mach-O format, and resource files
(and
sometimes libraries, etc...). And when you read first bytes, you get "fe
ed
fa ce" in hex dump.

OSX has still support for CFM (Code Fragment Manager) applications.
Indeed,
many carbon applications can run under both OS9 ans OSX. But XCode can
only
compile Mach-O, for one simple reason: it uses gcc as a compiler, an gcc
(under OSX) can only produce Mach-O executables.

I looked at several files of Office, and they are all PEF files (including
the Excel program). And if you look at folder /System/Library/CFMSupport/,
you should find CarbonLib and StdCLib (among others), put there when you
installed Office. So I think I can conclude Office is a carbon
application,
using the old CFM "model". But note Carbon applications can also be
compiled
in Mach-O apps, it's just a design choice. And I am almost certain you
will
need to compile CFM dynamic libs to be able to load them in Excel.
As I said above, XCode cannot do that. I suppose CodeWarrior can. And MPW
under OS9 certainly can.

If you have only OSX, Xcode and Office, I fear it's bad luck ;-)
But if you find a solution, I am interested ! I would be very happy to
compile dylibs for Excel...

---

So far I am using xlc++ as compiler. This is much more compatible with the
windows ms VC++ code.
If I have to I will try Code Warrior. If I understand you right, I have to
change my linking. The .o files should be
the same in both cases, Mach-O and CFM.

Is it possible to have CFM build under OS X or do I have to change to an
OS 9 operating system ?

If XCode does not allow to build CFM files. Is this possible by simple
makefiles and the dyld linker ?

how can I analyze a PEF file ? I tried with otool, buth I think this is
not the correct one.

Regards

Jurgen
 
J

Jean-Claude Arbaut

So far I am using xlc++ as compiler. This is much more compatible with the
windows ms VC++ code.

From what I've seen in the beta version of XLC, it can only produce Mach-O
binaries (compatible with gcc).
If I have to I will try Code Warrior. If I understand you right, I have to
change my linking. The .o files should be
the same in both cases, Mach-O and CFM.

No. In the Mach-O case, .o files are "full" Mach-O binaries.
In fact, there are several "types" of Mach-O files:
program executable, dylib, bundle, .o, and few other that I've never used.
Is it possible to have CFM build under OS X or do I have to change to an
OS 9 operating system ?

There are probably compilers that can handle that. *Maybe* CodeWarrior can,
I don't know (never used it).
If XCode does not allow to build CFM files. Is this possible by simple
makefiles and the dyld linker ?

No. ld and dyld work with Mach-O. I think CFM rely on
System/Library/Frameworks/Carbon.framework/Versions/A/Support/LaunchCFMApp.

how can I analyze a PEF file ?

There is PEF Viewer in /Developer/Applications/
Actually, there *was*, since I can't find it in the last XCode version
(2.1).

If you are interested, I think I still have an old XCode on some CD :)
I tried with otool, buth I think this is
not the correct one.

You are right, otool can only analyze a Mach-O file.
 
J

jjaeger

I thank you for answer on the CFM question. I build my shared libs using
the PEF file format with CodeWarrior.

But still I cannot call them from VBA inside Excel.

I compiled a shared lib under CodeWarrior on the small code :


double fplus (double invalue)
{
return invalue + 1.0;
}

This function is exported as the mangled name fplus__Fd (as I can see in
the PEFViewer)

I compared my shared lib to the CarbonLib, that comes with Microsoft
Office in /System/Library/CFMSupport
MySharedLib and CarbonLib have the same features using GetFileInfo and
PEFViewer

When I try to call fplus in VBA (Mac Excel 2004), the call gets the Error
454 - code resource not found.
The call to the fabs in the CarbonLib works fine.
Both files are found, as there is no error 53 - File not found for
MySharedLib

Here is the vba example :

Declare Function fabs Lib "CarbonLib" (i As Double) As Double
Declare Function fplus__Fd Lib "MySharedLib" (i As Double) As Double

Sub test()

Dim fabval As Double
fabval = fabs(-345.45)
MsgBox " value " & fabval
fabval = fplus__Fd(234.3)
End Sub

---

Do you have a quick explanation how to do the integration ?

A simple example of some lines in C++ and some lines in VBA would be
great.

Or do you know a pointer to someone that could help me on this ?

Thanks in advance for your help.

Regards

Jürgen Jäger

So far I am using xlc++ as compiler. This is much more compatible with the
windows ms VC++ code.

From what I've seen in the beta version of XLC, it can only produce Mach-O
binaries (compatible with gcc).
If I have to I will try Code Warrior. If I understand you right, I have to
change my linking. The .o files should be
the same in both cases, Mach-O and CFM.

No. In the Mach-O case, .o files are "full" Mach-O binaries.
In fact, there are several "types" of Mach-O files:
program executable, dylib, bundle, .o, and few other that I've never used.
Is it possible to have CFM build under OS X or do I have to change to an
OS 9 operating system ?

There are probably compilers that can handle that. *Maybe* CodeWarrior
can,
I don't know (never used it).
If XCode does not allow to build CFM files. Is this possible by simple
makefiles and the dyld linker ?

No. ld and dyld work with Mach-O. I think CFM rely on
System/Library/Frameworks/Carbon.framework/Versions/A/Support/LaunchCFMApp.

how can I analyze a PEF file ?

There is PEF Viewer in /Developer/Applications/
Actually, there *was*, since I can't find it in the last XCode version
(2.1).

If you are interested, I think I still have an old XCode on some CD :)
I tried with otool, buth I think this is
not the correct one.

You are right, otool can only analyze a Mach-O file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top