Click here to Skip to main content
15,916,527 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I pass images to and from the WebBrowser control??? Pin
DelphiCoder27-Oct-09 10:52
DelphiCoder27-Oct-09 10:52 
GeneralRe: How do I pass images to and from the WebBrowser control??? Pin
Abhishek Sur27-Oct-09 11:00
professionalAbhishek Sur27-Oct-09 11:00 
GeneralRe: How do I pass images to and from the WebBrowser control??? Pin
DelphiCoder27-Oct-09 13:59
DelphiCoder27-Oct-09 13:59 
GeneralRe: How do I pass images to and from the WebBrowser control??? Pin
Abhishek Sur27-Oct-09 22:43
professionalAbhishek Sur27-Oct-09 22:43 
QuestionButtons in screenpreview (Win7) Pin
_Madmatt27-Oct-09 9:48
_Madmatt27-Oct-09 9:48 
AnswerRe: Buttons in screenpreview (Win7) Pin
Dave Kreskowiak27-Oct-09 10:52
mveDave Kreskowiak27-Oct-09 10:52 
GeneralRe: Buttons in screenpreview (Win7) Pin
_Madmatt28-Oct-09 9:37
_Madmatt28-Oct-09 9:37 
QuestionDetecting Accessiblity Settings Pin
Sir Dot Net27-Oct-09 9:10
Sir Dot Net27-Oct-09 9:10 
QuestionPrinting in C# using built in printer fonts [modified] Pin
Jörgen Sigvardsson27-Oct-09 8:51
Jörgen Sigvardsson27-Oct-09 8:51 
AnswerRe: Printing in C# using built in printer fonts Pin
Luc Pattyn27-Oct-09 9:22
sitebuilderLuc Pattyn27-Oct-09 9:22 
GeneralRe: Printing in C# using built in printer fonts Pin
Jörgen Sigvardsson27-Oct-09 9:28
Jörgen Sigvardsson27-Oct-09 9:28 
AnswerRe: Printing in C# using built in printer fonts Pin
Sir Dot Net27-Oct-09 9:40
Sir Dot Net27-Oct-09 9:40 
GeneralRe: Printing in C# using built in printer fonts Pin
Jörgen Sigvardsson27-Oct-09 9:42
Jörgen Sigvardsson27-Oct-09 9:42 
GeneralRe: Printing in C# using built in printer fonts Pin
Luc Pattyn27-Oct-09 9:56
sitebuilderLuc Pattyn27-Oct-09 9:56 
GeneralRe: Printing in C# using built in printer fonts Pin
Jörgen Sigvardsson27-Oct-09 10:02
Jörgen Sigvardsson27-Oct-09 10:02 
GeneralRe: Printing in C# using built in printer fonts Pin
Luc Pattyn27-Oct-09 10:18
sitebuilderLuc Pattyn27-Oct-09 10:18 
GeneralRe: Printing in C# using built in printer fonts Pin
Jörgen Sigvardsson27-Oct-09 10:21
Jörgen Sigvardsson27-Oct-09 10:21 
QuestionHow to call a .dll written in unmanaged C++ from C# and pass structs to and from? [Solved] Pin
CircuitDoc27-Oct-09 8:05
CircuitDoc27-Oct-09 8:05 
AnswerRe: How to call a .dll written in unmanaged C++ from C# and pass structs to and from? Pin
Luc Pattyn27-Oct-09 8:28
sitebuilderLuc Pattyn27-Oct-09 8:28 
GeneralRe: How to call a .dll written in unmanaged C++ from C# and pass structs to and from? Pin
CircuitDoc27-Oct-09 8:58
CircuitDoc27-Oct-09 8:58 
GeneralRe: How to call a .dll written in unmanaged C++ from C# and pass structs to and from? Pin
Luc Pattyn27-Oct-09 9:17
sitebuilderLuc Pattyn27-Oct-09 9:17 
AnswerRe: How to call a .dll written in unmanaged C++ from C# and pass structs to and from? [Solved] Pin
CircuitDoc29-Oct-09 7:48
CircuitDoc29-Oct-09 7:48 
Thanks to Luc Pattyn and a little more reasearch on the Web, I solved this using the GCHandle Class.

Here is the updated working code:

public struct MY_Input_Type
       {
           public UInt32 iSignalCount;
           public IntPtr dSignal;
           public UInt32 iFilterCount;
           public IntPtr dFilterKernel;
       }

       public struct MY_Return_Type
       {
           public UInt32 iDftCount;
           public IntPtr dDft;
           public IntPtr dFilteredSignal;
       }
       [DllImport(@"MY_DLL.dll")]
       public static extern uint PowerOfTwo(uint b);
       [DllImport(@"MY_DLL.dll")]
       public static extern void FFT_Convolution(MY_Input_Type input, MY_Return_Type rtrn);

       public void Start(string rawFile, string filterFile, string outFile)
       {
           //Instantiate the input and return structs
           MY_Input_Type input;
           MY_Return_Type rtrn;

           //Create arrays to hold the data while in the C# program
           double[] filterData;
           double[] rawData;
           double[] returnData;
           double[] returnFilter;

           //Fill the input arrays with data from files.
           filterData = ReadFile(rawFile);
           rawData = ReadFile(filterFile);

           //Create handles for input arrays so they do not get Garbage collected
           GCHandle rawHandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
           GCHandle filterHandle = GCHandle.Alloc(filterData, GCHandleType.Pinned);

           //Set the pointers in the input struct equal to the address of the handles for the arrays
           input.dSignal = rawHandle.AddrOfPinnedObject();
           input.dFilterKernel = filterHandle.AddrOfPinnedObject();

           //Initialize input integers to the sizes of the arrays
           input.iFilterCount = Convert.ToUInt32(filterData.Length);
           input.iSignalCount = Convert.ToUInt32(rawData.Length);

           //Set counter in return struct to the size of the return arrays (input size rounded up to power of two)
           rtrn.iDftCount = PowerOfTwo(Convert.ToUInt32(rawData.Length));

           //Initialize the return arrays to the size needed for the return data
           returnData = new double[Convert.ToInt32(rtrn.iDftCount)];
           returnFilter = new double[Convert.ToInt32(rtrn.iDftCount)];

           //Create handles for output arrays so they do not get Garbage collected
           GCHandle rtrnData = GCHandle.Alloc(returnData, GCHandleType.Pinned);
           GCHandle rtrnFilter = GCHandle.Alloc(returnFilter, GCHandleType.Pinned);

           //Set the pointers in the output struct equal to the address of the handles for the arrays
           rtrn.dDft = rtrnData.AddrOfPinnedObject();
           rtrn.dFilteredSignal = rtrnFilter.AddrOfPinnedObject();

           //Call the function, feeding in the structs for the input and return
           FFT_Convolution(input, rtrn);

           //Write the data to a file
           WriteOutput(returnFilter, returnData, outFile);

           //Release Handles to free up the unmanaged memory
           rawHandle.Free();
           filterHandle.Free();
           rtrnData.Free();
           rtrnFilter.Free();
       }


If anyone sees a way to optimize this code, please let me know. Thanks...
QuestionPass string " Hello {0}" though MessageBox Pin
I Believe In GOD27-Oct-09 7:41
I Believe In GOD27-Oct-09 7:41 
AnswerRe: Pass string " Hello {0}" though MessageBox PinPopular
Luc Pattyn27-Oct-09 7:50
sitebuilderLuc Pattyn27-Oct-09 7:50 
GeneralRe: Pass string " Hello {0}" though MessageBox Pin
Keith Barrow27-Oct-09 7:56
professionalKeith Barrow27-Oct-09 7:56 

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.