Jump to content

New Plugin SDK Troubles...


Recommended Posts

@Jon or a C/C++ guru

I have downloaded and tried to use the new SDK that Jon updated due to our inability to use AU3_GetInt32(). (BTW I am not getting errors in relation to GetInt32 ne more so that is good).

The below are the errors I am getting.

Project : File-String Hash

Compiler : GNU GCC Compiler (called directly)

Directory : C:\Documents and Settings\Jarvis\My Documents\C++\AutoIt\Plugins\File-String Hash\

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

Switching to target: default

Compiling: au3plugin.cpp

au3plugin.cpp: In function `AU3_PLUGIN_VAR* AU3_AllocVar()':

au3plugin.cpp:30: error: invalid conversion from `void*' to `AU3_PLUGIN_VAR*'

au3plugin.cpp: In function `void AU3_SetString(AU3_PLUGIN_VAR*, const char*)':

au3plugin.cpp:89: error: invalid conversion from `void*' to `char*'

au3plugin.cpp: In function `char* AU3_GetString(const AU3_PLUGIN_VAR*)':

au3plugin.cpp:105: error: invalid conversion from `void*' to `char*'

au3plugin.cpp:133: error: invalid conversion from `void*' to `char*'

Process terminated with status 1 (0 minutes, 0 seconds)

4 errors, 0 warnings

It is only having trouble with the lines with malloc(). I tried including the <stdlib.h> header since I know that is where malloc() is located. This didnt solve anything so I removed that entry. I have not edited the au3plugin.cpp at all.

Also I am rather curious as to why the Plugin SDK is always in C? That may be my issue all together. I am trying to go C++, and I dont know quite enough about the differences between them to make it work. I have a working version up, but I have just been informed I have missed some error checking.

Thanks,

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Okay so far this seems to be working.

I replaced all malloc() functions with new, and replaced all free() functions with delete.

I compiled without any errors, or warnings.

Thanks everyone,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • Administrators

Weird. I'm sure I fixed this a while ago, maybe I lost a version somewhere.

malloc() returns a void* (i.e. a generic pointer to anywhere) and C happily accepts this without moaning. When you rename the file to .cpp the compiler usually forces C++ compilation and that is more strict about things.

Let's take line 105:

au3plugin.cpp:105: error: invalid conversion from `void*' to `char*'

char    *szString;
...
...
szString = malloc( strlen(pVar->m_szValue)+1 );

You can see that you are assigning malloc (void*) to szString (char *). C is happy for this to happen. C++ moans.

I need to change all these lines to have a cast like:

szString = (char *)malloc( strlen(pVar->m_szValue)+1 );

So then it will work in C and C++. I chose C because it was the lowest common denominator.

(btw. In this case you can probably get away with replacing malloc with new, but that's not always true as new does some other stuff too. And never free() something created with new, use delete)

Link to comment
Share on other sites

Weird. I'm sure I fixed this a while ago, maybe I lost a version somewhere.

malloc() returns a void* (i.e. a generic pointer to anywhere) and C happily accepts this without moaning. When you rename the file to .cpp the compiler usually forces C++ compilation and that is more strict about things.

Let's take line 105:

au3plugin.cpp:105: error: invalid conversion from `void*' to `char*'

char    *szString;
...
...
szString = malloc( strlen(pVar->m_szValue)+1 );

You can see that you are assigning malloc (void*) to szString (char *). C is happy for this to happen. C++ moans.

I need to change all these lines to have a cast like:

szString = (char *)malloc( strlen(pVar->m_szValue)+1 );

So then it will work in C and C++. I chose C because it was the lowest common denominator.

(btw. In this case you can probably get away with replacing malloc with new, but that's not always true as new does some other stuff too. And never free() something created with new, use delete)

I appreciate your response. I am still trying to learn as much about C++ mostly and the differences between it and C as much as possible.

What else does new do that malloc() doesnt? Maybe a link? I have searched a few of my most frequent C++ websites, and I havent really found anything.

If you would like you can look over my modified source as included in my zip file and possibly include a C and C++ version of the plugin so as to keep people from having to change the file extension. Or you can do as you said above and make it compatible that way.

Thanks for everything, and if there is anything else I can do to help with the plugins let me know.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • Administrators

What else does new do that malloc() doesnt? Maybe a link? I have searched a few of my most frequent C++ websites, and I havent really found anything.

Well first IIRC that malloc and new can allocate memory from different places - which is why you shouldn't mix new/free(). Also malloc just allocate memory, whereas new allocates memory of an object _and_ calls it's constructor (delete calls the destructor). If you're not working with objects you won't see a difference.

http://www.codeproject.com/tips/newandmalloc.asp

Link to comment
Share on other sites

Well first IIRC that malloc and new can allocate memory from different places - which is why you shouldn't mix new/free(). Also malloc just allocate memory, whereas new allocates memory of an object _and_ calls it's constructor (delete calls the destructor). If you're not working with objects you won't see a difference.

http://www.codeproject.com/tips/newandmalloc.asp

Yea I am not mixing new and malloc, but at the same time that is just in the SDK. So far I havent noticed any adverse affects with my plugin and AutoIt.

Thanks for the link,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Hi @JS,

You probably have this allready but better to be sure than sorry :P

Bruce Eckle "Thinking in C++ Vol 1" discusses the diffrence between C and C++ in the first few chapters.

I also found that the book (pdf) Object Oriented Programming with ANSI C turned on quite a few small lightbulbs in my head (regaridng C/C++) when I studied it.

Link to comment
Share on other sites

Hi @JS,

You probably have this allready but better to be sure than sorry :P

Bruce Eckle "Thinking in C++ Vol 1" discusses the diffrence between C and C++ in the first few chapters.

I also found that the book (pdf) Object Oriented Programming with ANSI C turned on quite a few small lightbulbs in my head (regaridng C/C++) when I studied it.

Thanks Uten. I actually havent had the chance to read Thinking in C++ yet. I appreciate the link. I will bookmark that for my next read.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...