如何从C#中的标准DLL win32加载图像? [英] How to load image from a standard DLL win32 in C#?

查看:108
本文介绍了如何从C#中的标准DLL win32加载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我用C ++创建了一个带有一些图像的标准dll win32文件。现在我必须从这个dll加载一个图像(带有ID)。我想使用API​​函数加载该图像,并在我的PictureBox控件Form上显示它。但我不知道选择任何功能并使用它。我该怎么做呢?希望你帮帮我。谢谢。



我尝试过:



这是我的代码:我使用

Hi everyone,
I have created a standard dll win32 file with some images by C++. Now I have to load a image (which is with ID) from this dll. I want to use a API function to load that image and after display it on my PictureBox control of Form. But I dont know to choose any function and use it. How do I do this? Hope you help me. Thanks.

What I have tried:

This is my code: I use

LoadBitmapA

函数。



function.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Runtime.InteropServices;

namespace ImageDLLTest
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern IntPtr LoadBitmapA(IntPtr hinst, int iD);
        [DllImport("kernel32.dll")]
        private static extern IntPtr LoadLibraryA(string Libb);
        [DllImport("kernel32.dll")]
        private static extern IntPtr FreeLibrary(IntPtr hinst);

        public Form1()
        {
            InitializeComponent();
            IntPtr getLib = LoadLibraryA("xy.dll");
            this.BackgroundImage = (System.Drawing.Image)LoadBitmapA(getLib, 1);
            IntPtr freeLib = FreeLibrary(hinst);

            //MessageBox.Show(getLib.ToString());
        }
    }
}





但是没有用!



But not work!

推荐答案

您必须使用某些功能构建一些接口。



所需的步骤是:



1.从C ++图像中获取所有需要的信息到C# app

2.在C#中构建一个合适的字节缓冲区

4.调用C ++用图像数据填充字节缓冲区

4.构造位图



然后你可以使用这个位图构造函数来构建你的位图。



要在你的dll中编写一个界面,你可以从我的文章中学习呼叫所有电台



一个黑客将是dll写的加载C#的临时位图文件。
You must build some interface with some functionality.

The needed steps are:

1. fetch all needed information from the C++ image into the C# app
2. build a suitable byte buffer in C#
4. call C++ to fill the byte buffer with the image data
4. construct the bitmap

Then you can use this Bitmap constructor to build your bitmap.

To write an interface in your dll you can learn from my article Calling All Stations.

A hack would be that the dll writes a temporary bitmap file which loads C#.


这篇关于如何从C#中的标准DLL win32加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆