Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6709 Discussions

A problem with System.DllNotFoundException in the dll file created by including ippiFFTGetSize_C_32fc ().

chang_mo__ku
Beginner
1,730 Views

I created a dll created using the IPP function ippiFFTGetSize_C_32fc (). Referencing this dll file from wpf project (c #) results in "System.DllNotFoundException: Unable to load DLL 'TEST.dll'" error.

=========================================================================================

// C/C++ export.def

LIBRARY

EXPORTS
ippiFFTGetSize_C_32fc

 

 

// C/C++ dllMain.cpp

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "stdafx.h"
#include "HIOTEST.h"
#include "ipp.h"

BOOL WINAPI DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{

    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
		ippInit();
		break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

 

 

// C/C++ HIOTEST.h

#pragma once
#include "ipp.h"

#ifdef HIOTEST_EXPORTS
#define HIOTEST_API extern "C" __declspec(dllexport)
#else
#define HIOTEST_API extern "C" __declspec(dllimport)
#endif

HIOTEST_API int HioTest(Ipp32fc* csSrcImg, Ipp32fc* csDstImg);

 

 

// C/C++ HIOTEST.cpp

#include "stdafx.h"
#include "ipp.h"
#include "ippi.h"
#include "ipptypes.h"
#include "HIOTEST.h"

#include "ippcore.h"
#include "ippvm.h"
#include "ipps.h"


int HioTest(Ipp32fc* csSrcImg, Ipp32fc* csDstImg)
{

	// FFT Init
	IppiFFTSpec_C_32fc  *pSpec = NULL;                              /* Pointer to FFT spec structure */
	Ipp8u               *pMemInit = NULL, *pBuffer = NULL;          /* Pointer to the work buffers */
	int                 sizeSpec = 0, sizeInit = 0, sizeBuf = 0;    /* Size of FFT spec structure, init and work buffers */
	int               order = 9;

	ippiFFTGetSize_C_32fc(order, order, IPP_FFT_DIV_INV_BY_N, ippAlgHintAccurate, &sizeSpec, &sizeInit, &sizeBuf);

	return 5;
}

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

// C# (HIO_exe.sln)  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Numerics;

namespace HIO_exe
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public struct CsIpp32fc
        {
            public float real, im;
        }

        [DllImport("HIOTEST.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern int HioTest(ref CsIpp32fc csSrcImg, ref CsIpp32fc csDstImg);

        public string imgPath;
        public Image origin = new Image();
        public BitmapSource dstImg;
        // FuctionWithIpp.dll Load

        public MainWindow()
        {
            InitializeComponent();
        }


        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            // file open
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.InitialDirectory = @"C:\Desktop";
            openDialog.Filter = "Image Files | *.jpg; *.png; *.tif; *.bmp; *.tiff";

            openDialog.CheckFileExists = true;
            openDialog.CheckPathExists = true;

            if(openDialog.ShowDialog().GetValueOrDefault())
            {
                imgPath = openDialog.FileName;
                BitmapImage bitmap = new BitmapImage(new System.Uri(openDialog.FileName));

                SrcCanvas.Source = bitmap;
                SrcCanvas.Width = tabBorder.Width;
                SrcCanvas.Height = tabBorder.Height;

                srcWidth.Content = bitmap.PixelWidth;

                
            }


        }

        private void Run_Click(object sender, RoutedEventArgs e)
        {
            BitmapImage LoadBitMap = new BitmapImage(new System.Uri(imgPath));
            int stride = LoadBitMap.PixelWidth;
            int size = LoadBitMap.PixelHeight * stride;
    
            byte[] srcImg = new byte[size];
            LoadBitMap.CopyPixels(srcImg, stride, 0);

            CsIpp32fc[] CsSrcImg = new CsIpp32fc[size];
            CsIpp32fc[] CsDstImg = new CsIpp32fc[size];
            for(int i = 0; i < size; i++)
            {
                CsSrcImg.real = srcImg;
            }

// Error Point!!!
            int res = HioTest(ref CsSrcImg[0], ref CsDstImg[0]);
// Error Point!!!

            byte[] result = new byte[size];
            for(int i = 0; i < size; i++)
            {
                result = (byte)CsDstImg.real;
            }
            dstImg = BitmapSource.Create(LoadBitMap.PixelWidth, LoadBitMap.PixelHeight, 300, 300, PixelFormats.Gray8, BitmapPalettes.Gray256, result, stride);

            DstCanvas.Source = dstImg;
            DstCanvas.Width = tabBorder.Width;
            DstCanvas.Height = tabBorder.Height;

            
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.InitialDirectory = @"C:\Desktop";
            saveDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveDialog.Title = "Save an Image File";
            saveDialog.ShowDialog();

            string saveFilePath = saveDialog.FileName;

            using (var fileStream = new System.IO.FileStream(saveFilePath, System.IO.FileMode.Create))
            {
                BitmapEncoder encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(dstImg));
                encoder.Save(fileStream);

                fileStream.Close();
            }
            
        }
    }
}

========================================================================================

I created a TEST.dll (C language) using IPP for External library. I want to refer to TEST.dll in my wpf project and use it.

 

The tool used is "visual studio 2017" and the IPP version uses the latest version of 'compilers_and_libraries_2019.1.144'.

 

See the IPP documentation. The settings of the dll project,

- Debug / x64

- Add "ippsmt.lib, ippcoremt.lib “ for 'Additional Dependencies' ".

- Automatic "single-threaded DLL" setting.

- 'export .def' created.

- Add ippInit () to dllmain.cpp

- Referencing from C # . /clr setting

 

C # project

- Debug / x64

- unlock the loader

- Increase the reserve stack size

 

I set it up like this.

Other ippMalloc (), ippsAdddC_32f_I ()
The dll file I created using the above worked properly in my wpf project. However, TEST.dll containing ippiFFTGetSize_C_32fc () will result in an error "System.DllNotFoundException: Unable to load DLL 'TEST.dll'".
I want to know the cause or solution.

 

 

0 Kudos
3 Replies
Igor_A_Intel
Employee
1,730 Views

Hi,

I guess you've used "copy-past" for your question and several lines of your problem description are broken. Could you provide the full description of your problem?

regards, Igor

0 Kudos
chang_mo__ku
Beginner
1,730 Views

Thank you for pointing out my wrong question. Using the first question on the Intel forum, it was a lot lacking. Sorry.

I wrote down all the code for the two projects I wrote.

0 Kudos
Igor_A_Intel
Employee
1,730 Views

Hi Ku,

could you replace all references to IPP functions in your code with something like

printf("Hello world\n!");

?

What is happened in this case? just in order to be sure that something is wrong with IPP...

regards, Igor

 

0 Kudos
Reply