在Silverlight中使用自定义DLL
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I'm testing and trying to understand how to create a DLL and call a function from it in my Silverlight project. I'm getting an exception: Unable to find an entry point named 'WriteTextFile' in DLL 'C:\temp\TestDLL.dll'. So I'm doing something wrong.

Here is my code for the very simple DLL:

Imports System.IO

Public Class Class1

    Private Shared dir As String = "C:\TEMP"
    Private Shared file As String = "TestDLL.txt"

    Public Shared Sub WriteTextFile()
        Using wr As New StreamWriter(System.IO.Path.Combine(dir, file))
            wr.WriteLine("Call to function WriteTextFile()")
        End Using
    End Sub

End Class

And this is what I'm doing in my Silverlight:

Imports System.Runtime.InteropServices


Partial Public Class MainPage
    Inherits UserControl

    <DllImport("C:\temp\TestDLL.dll")> _
    <AllowReversePInvokeCalls()> _
    Friend Shared Sub WriteTextFile()
    End Sub

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        WriteTextFile()
    End Sub

End Class

I need some pointing to the right direction here :)

The AllowReversePInvokeCalls part is just something I tried out after doing some reading around the web but it didn't change anything. Also I've tried to set the EntryPoint in the DLLImport but that doesn't do anything either.

Edit:

I tried this DLL and pinvoke in regular WPF application and I get the same error so this is not related to Silverligth. Maybe in my DLL then?

#0

Ok, so it looks like this can't be done simply because using pinvoke requires a standard dll and I can't do those with VB .NET. So I'll need to try something else :)

If anyone has more information about this and like to share it I would appreciate that. Or correct me if I've understood the issue wrong.

推荐文章

另类网址加密方法 - IP地址进制转换

另类网址加密方法 - IP地址进制转换

推荐文章

微信小游戏-开放数据域的配置

微信小游戏-开放数据域的配置

推荐文章

侃侃处理帐号的事

侃侃处理帐号的事

推荐文章

Elasticsearch - 处理冲突

Elasticsearch - 处理冲突

推荐文章

百度2015 在线笔试题(1)

百度2015 在线笔试题(1)

推荐文章

微信小程序实现转义换行符

微信小程序实现转义换行符

推荐文章

百度2015 在线笔试题(2)

百度2015 在线笔试题(2)

推荐文章

分布式搜索elasticsearch 索引文档的增删改查(RESTful)

分布式搜索elasticsearch 索引文档的增删改查(RESTful)

推荐文章

百度2015 在线笔试题(3)

百度2015 在线笔试题(3)

推荐文章

Elasticsearch - 配置详解

Elasticsearch - 配置详解

推荐文章

微信小程序 | canvas绘图

微信小程序 | canvas绘图

推荐文章

统计URL出现的频次

统计URL出现的频次

推荐文章

CentOS MINI使用日记(一)

CentOS MINI使用日记(一)

推荐文章

利用Python网络爬虫抓取微信好友的所在省位和城市分布及其可视化

利用Python网络爬虫抓取微信好友的所在省位和城市分布及其可视化

推荐文章

百度测试开发9/16/2015

百度测试开发9/16/2015

推荐文章

微信APP支付

微信APP支付