Archicad C++ API
About Archicad add-on development using the C++ API.

Addon getting information from external database (MySQL)

Anonymous
Not applicable
Hi all!

I have the following problem:
I need to make an addon for Archicad12, that operates with data from mysql database. I wrote basic addon with some menu and handlers for them, now i need to connect to mysql, but can't do anything.

I tried to use OdbcConnection from System.Data.dll, but to compile such a project I need to use /clr compilation option that conflicts with /Gr (__fastcall), so here I got nothing.
Then I tried to use mysql++ api, after reading manual and cleaning all errors addon was built, but AC wrote me something about addon is old for current version... 😞 (commenting all places of using external functions makes addon up-to-date - it's magic). What's the problem with it here?

Can anybody help me to connect to Mysql in any way?

P.S. I use MS Visual Studio 2005.
8 REPLIES 8
Oleg
Expert
Hi Ivan,

I am sorry, I cannot help to connect to MySQL as I do not know the subject. But I have one idea about possible reason.
May be there are dependencies on some external DLLs, after linking to mysql++ library. May be DLLs are not found and addon is not loaded. It is just a guess, but check up DLL dependences and put it into right place, if it is.

Oleg.
Anonymous
Not applicable
I created my own simple dll with function returning just number, connected it to my archicad addon project, compiled it (without errors and visual studio could get an access to my dll for sure) and Archicad wrote me the same message...
I don't know why, but I consider Archicad doesn't like addons using external, not his native libraries. It's a pity...
But I don't see another way, because I need to 1)build objects on my model,2)get its description,3)probably change this data (it's optional) according to entries in my external database.

Does Archicad gives such an opportunity??
Ralph Wessel
Mentor
Ivan wrote:
Then I tried to use mysql++ api, after reading manual and cleaning all errors addon was built, but AC wrote me something about addon is old for current version... (commenting all places of using external functions makes addon up-to-date - it's magic). What's the problem with it here?
The message that "the add-on is an old version" is really a euphemism for "something went wrong when the add-on was loaded but I don't know why".

It could be a problem with loading dynamic libraries. I haven't linked an add-on to MySQL, so I can't be certain. I have used many other APIs with add-ons though, and you generally have an option for static or dynamic linking with 3rd party SDKs. I would recommend trying static linking if possible.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
How can I understand which dlls can I use?
I tried native mysql.h header and libraries and had the same...

Could you show me some examples of your usage of libraries? have you tried to connect to any database?
And can I use system package (e.g. system.data.odbc)?
Oleg
Expert
Ivan wrote:
I created my own simple dll with function returning just number, connected it to my archicad addon project, compiled it (without errors and visual studio could get an access to my dll for sure) and Archicad wrote me the same message...
Where you place this test dll ?
Try to put it into root folder of Archicad and do the test.

PS:
I am use number of DLLs (mine and third party), but I load it by LoadLibraryEx etc. May be something changed, but if I remember well, there was a problem and external DLL you linked can not be placed at your AddOn's place.

Oleg
Anonymous
Not applicable
Thanks for advice!
I put it into Archicad folder and addon launched.
So,I must put every dll I use into Archicad folder?

I never wrote dlls, could you show me the example of how to use LoadLibraryEx inside archicad addon and to access to this dll?
I will be grateful to you very much!!!
Oleg
Expert
Ivan wrote:
So,I must put every dll I use into Archicad folder?
If you will use so-called "load-time dynamic linking" linking to corresponding lib for dll, then you DLL have to placed into one of locations which Windows will search. (see details in the MSDN)
So it is Archicad or System32 or Windows folders (last may be your option for MySql)
Ivan wrote:
I never wrote dlls, could you show me the example of how to use LoadLibraryEx inside archicad addon and to access to this dll?
Other way is so called "run-time dynamic linking". You dont link to the lib of dll. You have to load it directly by LoadLibrary ( or LoadLibraryEx ), then GetProcAddress for every functions you will use. This way is more hard.
See MSDN for details as it is long story.

I dont think there is one best universal way. It is dependent on details etc.

If you wish use MySQL universally and many functions of it's API, then may be better way to install DLLs into Windows folder.

If you want do limited, specific using of MySql, then may be better other way:
create your dll, which will do your specific tasks, export functions from it.
Link this dll directly to MySql libs ("load-time dynamic linking").
Place this dll and all MySQL's dll at your AddOn. Dont link the Addon to the DLL. Load the DLL by LoadLibraryEx with LOAD_WITH_ALTERED_SEARCH_PATH flag, so MySql DLLs will loaded automatically.
Do GetProcAddress for your exported functions and use it.

I think it is sound complex (and my poor English too), so may be better for just to put external DLLs into Windows folder.

Good luck

Oleg
Anonymous
Not applicable
You told me what I looked for VERY much time! THANKS!

I'll try to do this!

Can I communicate with you in case of any troubles by e-mail (what is it?)?