Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: Object cannot be cast from DBNull to other types. Pin
Anthony Mushrow11-Dec-07 4:12
professionalAnthony Mushrow11-Dec-07 4:12 
GeneralRe: Object cannot be cast from DBNull to other types. Pin
Pete O'Hanlon11-Dec-07 5:26
mvePete O'Hanlon11-Dec-07 5:26 
GeneralPassing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
f4hd11-Dec-07 3:14
f4hd11-Dec-07 3:14 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
m@u11-Dec-07 3:25
m@u11-Dec-07 3:25 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
f4hd11-Dec-07 3:46
f4hd11-Dec-07 3:46 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
m@u11-Dec-07 4:15
m@u11-Dec-07 4:15 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
f4hd11-Dec-07 8:33
f4hd11-Dec-07 8:33 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
m@u11-Dec-07 22:33
m@u11-Dec-07 22:33 
f4hd wrote:
not quite elegant, is to convert the 2d arrays into 1d arrays during passing and receiving... Can there be any better way I wonder?


well if you can make it work that way i think that's a good way. an other way you could try would be to pass an array of intptrs that point each to an array of float.
it's ugly and i don't really know if it'll work at all but it *might* work Smile | :)
that it would look like this:

DllImportAttribute(@".\xyz_MFC.dll")]
public static extern bool Evaluate(IntPtr [] input, IntPtr[] output, int nFrames,int featureWidth);
private float[,] foo()
{
    int nFrames = 3; // change these 2 values to appropriate vals
    int featurWidth = 5; // ...
    float[,] myArray = new float[2,nFrames];
    // fill your values here...
    IntPtr[] input = writeArray(myArray);
    IntPtr[] output = allocArray(featurWidth);
    bool ok = Evaluate(input, output, nFrames, featurWidth);
    freeArray(input);
    return readArray(output,featurWidth);
}
private float[,] readArray(IntPtr[] Items, int featureWidth)
{
    float[,] RetVal = new float[2,featureWidth];
    readMemArray(Items[0],RetVal,0,featureWidth);
    readMemArray(Items[1],RetVal,1,featureWidth)
    freeArray(Items);
    return RetVal;
}
private void readMemArray(IntPtr Pointer, Float[,] Target, int Dimension, int featureWidth)
{
   float[] Dummy = new float[featureWidth];
   Marshal.Copy(Pointer,Dummy,0,featureWidth);
   copyArray(Dummy, Target, Dimension);
}
private void freeArray(IntPtr[] Items)
{
    Marshal.FreeHGlobal(Items[0]);
    Marshal.FreeHGlobal(Items[1]);
}
private IntPtr[] allocArray(int ItemCount)
{
    IntPtr RetVal = new IntPtr[2];
    int Count = Marshal.SizeOf(typeof(float)) * ItemCount;
    RetVal[0] = Marshal.AllocHGlobal(Count);
    RetVal[1] = Marshal.AllocHGlobal(Count);
    return RetVal;
}
private IntPtr[] writeArray(float[,] Array)
{
    IntPtr[] RetVal = allocArray(Array.GetLength(1));
    float[] Dummy = new float[Array.GetLength(1)];
    copyArray(Array, Dummy, 0);
    Marshal.Copy(Dummy,0,RetVal[0],Dummy.Length);
    copyArray(Array, Dummy, 1);
    Marshal.Copy(Dummy,0,RetVal[1],Dummy.Length);
}
private void copyArray(float[] Source, float[,] Destination, int zDimIndex)
{
    for(int i = 0; i< Source.Length; i++)
    {
        Destination[zDimIndex,i] = Source[i];
    }
}
private void copyArray(float[,] Source, float[] Destination, int zDimIndex)
{
    for(int i = 0; i < Destination.Length; i++)
    {
        Destination[i] = Source[zDimIndex,i];
    }
}


the code is untested so maybe you'll have to change something but generally it could work.
however.. if you can make it work with an 1-dimensional array do it that way Smile | :)

greets
m@u
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
f4hd13-Dec-07 4:23
f4hd13-Dec-07 4:23 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
m@u13-Dec-07 5:02
m@u13-Dec-07 5:02 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
Skippums11-Dec-07 9:02
Skippums11-Dec-07 9:02 
GeneralRe: Passing dynamic 2 dim float array in c# to unmanaged c++ dll Pin
f4hd11-Dec-07 9:34
f4hd11-Dec-07 9:34 
Questionregarding to dll hell with code Pin
creative2002guy11-Dec-07 2:57
creative2002guy11-Dec-07 2:57 
GeneralRe: regarding to dll hell with code Pin
Pete O'Hanlon11-Dec-07 3:17
mvePete O'Hanlon11-Dec-07 3:17 
GeneralRe: regarding to dll hell with code Pin
Colin Angus Mackay11-Dec-07 3:22
Colin Angus Mackay11-Dec-07 3:22 
JokeRe: regarding to dll hell with code Pin
Luc Pattyn11-Dec-07 4:15
sitebuilderLuc Pattyn11-Dec-07 4:15 
GeneralRe: regarding to dll hell with code Pin
creative2002guy11-Dec-07 7:09
creative2002guy11-Dec-07 7:09 
GeneralEnterprise Library configuration tool Pin
PaulPrice11-Dec-07 2:19
PaulPrice11-Dec-07 2:19 
Generaldatatable column size Pin
arkiboys11-Dec-07 1:55
arkiboys11-Dec-07 1:55 
GeneralRe: datatable column size Pin
pmarfleet11-Dec-07 2:47
pmarfleet11-Dec-07 2:47 
Generalerror in execution of SSIS package.. Pin
tasumisra11-Dec-07 1:05
tasumisra11-Dec-07 1:05 
GeneralRe: error in execution of SSIS package.. Pin
pmarfleet11-Dec-07 2:48
pmarfleet11-Dec-07 2:48 
GeneralRe: error in execution of SSIS package.. Pin
mecca15-Feb-09 7:17
mecca15-Feb-09 7:17 
Generaldatagridview cell size limit Pin
arkiboys11-Dec-07 0:31
arkiboys11-Dec-07 0:31 
GeneralPop3 mail attachment download Pin
energeticsridhar11-Dec-07 0:18
energeticsridhar11-Dec-07 0:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.