Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to download .exe files on click of link in asp.net Pin
Christian Graus6-May-08 19:14
protectorChristian Graus6-May-08 19:14 
AnswerRe: how to download .exe files on click of link in asp.net Pin
Vasudevan Deepak Kumar6-May-08 19:23
Vasudevan Deepak Kumar6-May-08 19:23 
AnswerRe: how to download .exe files on click of link in asp.net Pin
Shorgov6-May-08 22:08
Shorgov6-May-08 22:08 
GeneralRe: how to download .exe files on click of link in asp.net Pin
NarVish7-May-08 0:18
NarVish7-May-08 0:18 
Questionhow can i pass a text to crystal report from another form in c# Pin
imannasr6-May-08 17:50
imannasr6-May-08 17:50 
AnswerRe: how can i pass a text to crystal report from another form in c# Pin
Gopal.S6-May-08 20:19
Gopal.S6-May-08 20:19 
GeneralRe: how can i pass a text to crystal report from another form in c# Pin
imannasr6-May-08 20:40
imannasr6-May-08 20:40 
QuestionC# interop issue for C image resource Pin
BSOD26006-May-08 16:29
BSOD26006-May-08 16:29 
I'm writing a C# plugin for a C app, which has well defined API's, structures, etc. I'm trying to figure out how to use a icon / image resource in my C# project and properly convert it to the C struct.

For example, the C struct I have to use is:
struct medium_entry<br />
{<br />
    unsigned int                struct_size;<br />
<br />
    char                        *medium;<br />
    char                        *description;<br />
    int                         allows_accounts;<br />
    int                         allows_connections;<br />
<br />
    ttkCallback                 callback;<br />
    void                        *data;<br />
<br />
    unsigned char               *png_image_32;<br />
    unsigned int                png_image_32_len;<br />
    unsigned char               *png_image_16;<br />
    unsigned int                png_image_16_len;<br />
};


Here is the C# representation of that struct, which the P/Invoke Interop Assistant tool (winsiggen.exe) generated for me:
<br />
    [StructLayoutAttribute( LayoutKind.Sequential )]<br />
    public class medium_entry<br />
    {<br />
        /// unsigned int<br />
        public uint struct_size;<br />
<br />
        /// char*<br />
        [MarshalAsAttribute( UnmanagedType.LPStr )]<br />
        public string medium;<br />
<br />
        /// char*<br />
        [MarshalAsAttribute( UnmanagedType.LPStr )]<br />
        public string description;<br />
<br />
        /// ttkCallback<br />
        public ttkCallback callback;<br />
<br />
        /// void*<br />
        public System.IntPtr data;<br />
<br />
        /// unsigned char*<br />
        [MarshalAsAttribute( UnmanagedType.LPStr )]<br />
        public string png_image_32;<br />
<br />
        /// unsigned int<br />
        public uint png_image_32_len;<br />
<br />
        /// unsigned char*<br />
        [MarshalAsAttribute( UnmanagedType.LPStr )]<br />
        public string png_image_16;<br />
<br />
        /// unsigned int<br />
        public uint png_image_16_len;<br />
<br />
        public medium_entry_t()<br />
        {<br />
            this.struct_size = (uint)Marshal.SizeOf( typeof( medium_entry ) );<br />
        }<br />
    }<br />


Here is sample code on how the image would be loaded in C:
<br />
 HRSRC ImageRes;<br />
 data *medium_entry; // the structure given by the app<br />
 HMODULE hInstance; // the handle of your DLL instance, passed in through DLLMain<br />
<br />
 ImageRes = FindResource(hInstance, MakeIntResource(102), "PNG");<br />
 data->png_image_32 = LockResource(LoadResource(hInstance, ImageRes));<br />
 data->png_image_32_len = SizeOfResource(hInstance, ImageRes);<br />


I've tried two different methods of loading up an image and storing it in the medium_entry class, but neither have worked in the C app, so I assume I'm doing something wrong.

The managed way:
<br />
Bitmap bmp = null;<br />
System.IO.Stream imgStream = thisExe.GetManifestResourceStream( "Plugin.Resources.online_16x16.png" );<br />
<br />
bmp = Bitmap.FromStream( imgStream ) as Bitmap;<br />
if ( !( null == bmp ) )<br />
{<br />
    Rectangle rect = new Rectangle( 0, 0, bmp.Width, bmp.Height );<br />
    BitmapData bmpData = bmp.LockBits( rect, ImageLockMode.ReadOnly, bmp.PixelFormat );<br />
    MediumEntry.png_image_16 = bmpData.Scan0;<br />
    MediumEntry.png_image_16_len = (uint)imgStream.Length;<br />
<br />
    // Unlock the bits.<br />
    bmp.UnlockBits( bmpData );<br />
}<br />


The C interop way:
<br />
IntPtr hMod = WinLoadApi.LoadLibraryEx(Pathtoatestdllwithpngimage, IntPtr.Zero, WinLoadApi.LOAD_LIBRARY_AS_DATAFILE);<br />
IntPtr hRes = WinLoadApi.FindResource(hMod, 209, "PNG");<br />
MediumEntry.png_image_16 = WinLoadApi.LoadResource(hMod, hRes);<br />
MediumEntry.png_image_16_len = WinLoadApi.SizeofResource(hMod, hRes);<br />


1) Should png_image_32/16 really be an IntPtr instead of String? I've tried both ways in code (actually the code above mostly uses IntPtr).
2) What am I missing, because I simply can't get ANY sort of image loaded from C# to show up in the C. app using its defined structure.
QuestionOpening a comma delimited file in a spread sheet program Pin
ketto6-May-08 15:34
ketto6-May-08 15:34 
AnswerRe: Opening a comma delimited file in a spread sheet program Pin
Christian Graus6-May-08 15:38
protectorChristian Graus6-May-08 15:38 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
ketto6-May-08 15:45
ketto6-May-08 15:45 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
Christian Graus6-May-08 15:57
protectorChristian Graus6-May-08 15:57 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
ketto6-May-08 17:39
ketto6-May-08 17:39 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
Christian Graus6-May-08 17:49
protectorChristian Graus6-May-08 17:49 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
ketto6-May-08 19:23
ketto6-May-08 19:23 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
Christian Graus6-May-08 19:25
protectorChristian Graus6-May-08 19:25 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
ketto6-May-08 19:30
ketto6-May-08 19:30 
GeneralRe: Opening a comma delimited file in a spread sheet program Pin
Spacix One7-May-08 3:04
Spacix One7-May-08 3:04 
QuestionHow to print data to screen in C# Pin
mary okon6-May-08 15:29
mary okon6-May-08 15:29 
AnswerRe: How to print data to screen in C# Pin
Christian Graus6-May-08 15:37
protectorChristian Graus6-May-08 15:37 
GeneralRe: How to print data to screen in C# Pin
mary okon6-May-08 15:41
mary okon6-May-08 15:41 
AnswerRe: How to print data to screen in C# Pin
javedk096-May-08 20:01
javedk096-May-08 20:01 
QuestionChat Building - transfering data between server and client Pin
nelsonpaixao6-May-08 15:03
nelsonpaixao6-May-08 15:03 
AnswerRe: Chat Building - transfering data between server and client Pin
Reelix6-May-08 21:10
Reelix6-May-08 21:10 
QuestionGetting an Angle for Rotations Pin
RedHotFunk6-May-08 14:28
RedHotFunk6-May-08 14:28 

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.