roidy said:
Thanks guys for the help,
The actual function I`m trying to use is from libmp4v2.dll, the function is
called MP4GetMetadataCoverArt and is used to extract a piece of artwork from
a mp4 file heres the c code:-
declaration:-
bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
uint8_t** coverart,
uint32_t* size,
uint32_t index);
defination:-
bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
uint8_t **coverArt,
uint32_t* size,
uint32_t index)
{
if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
try {
return ((MP4File*)hFile)->GetMetadataCoverArt(coverArt, size, index);
}
catch (MP4Error* e) {
PRINT_ERROR(e);
delete e;
}
}
return false;
}
usage:-
uint8_t *art;
uint32_t artsize;
MP4GetMetadataCoverArt(filehandle, &art, &artsize);
When the function returns art is a pointer to a byte array that has been
filled with the coverart data and artsize is the size in bytes of that data.
So I carn`t just create a byte array to pass to the function because I dont
know the size until the function returns. Mike while I understand your code
it assumes you already know the size of the data your working with(my fault
I messed up the intial description of the function, I was just trying to
keep it simple
![Smile :) :)](/styles/default/custom/smilies/smile.gif)
.
Which brings me back to my original problem how do I pass a pointer to a
function when the memory hasn`t been allocated yet? eg.
char *data;
function(&data);
One approach to this is create a Managed Class Library (MCL)- a .NET
DLL wrapper around the unmanaged (traditional) library.
You MCL will do all your pointer and resources management
So you have:
libmp4v1.dll <--> MCL.DLL <--> .NET Application Lanaguages
The memory managemen is now in the MLC.DLL
The beauty of .NET is that you can create the MCL in any .NET
language, VB.NET, C++ (MS's C++/CLR) and C#.
This is what I am doing myself. The hard part is dealing with the
..NET interop interfaces, which includes also making functions return
arrays.
So you might have this, in the MCL.DLL a class, which you might want
to do in C#, C++ or VB.NET, whatever is easier for you:
in VB.NET, (not 100% correct here, just an outline)
public class MP4LIB
implements iDisposable
Private stuff() as Array
public shared function MP4GetMetadataCoverArt() as Byte()
// find size and allocate local memory
// call unmanaged function
// prepare byte array to return
// deallocate local memory
// return Byte array
end function
// constructor
sub new
// allocate stuff
end sub
// destructors (VB.NET style)
sub finalize
end sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
// deallocate stuff
end sub
end class
Thats the basic idea. I have over 100 functions to deal with
different signatures, some are easy to do in VB.NET, others are harder
so currently, I am mixing my MCL with VB.NET and C++, but I am also
learning how do the more complex stuff in VB.NET too.
Start by creating a class library with the functions your want that
will map the libmp4v2.dll. They exposed .NET function do not need to
be the same prototype, it can turn the array, like above.
--