Windows中使用GHCI的Haskell外部函数接口(Haskell Foreign Function Interface with GHCI in Windows)
首先,我指定使用Windows 10 64位和Haskell Platform 8.0.1。
我尝试使用以下代码在Windows中使用Haskell的FFI。
import Control.Monad import Data.Char import Foreign.C getCh :: IO Char getCh = liftM (chr . fromEnum) c_getch foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt main :: IO () main = getCh >>= \x -> print x
在此之后,我可以用ghc编译好
> ghc Examples.hs [1 of 1] Compiling Main ( Examples.hs, Examples.o ) Linking Examples.exe ...
它完全运行。
> Examples.exe '1'
(运行后输入1时)
但是,GHCI会出现问题。 当我把它加载到ghci时,我收到了这些消息。
> ghci Examples.hs GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Examples.hs, interpreted ) Ok, modules loaded: Main. *Main> main ByteCodeLink: can't find label During interactive linking, GHCi couldn't find the following symbol: getch This may be due to you not asking GHCi to load extra object files, archives or DLLs needed by your current session. Restart GHCi, specifying the missing library using the -L/path/to/object/dir and -lmissinglibname flags, or simply by naming the relevant files on the GHCi command line. Alternatively, this link failure might indicate a bug in GHCi. If you suspect the latter, please send a bug report to: glasgow-haskell-bugs@haskell.org *Main>
我尝试加载“缺少库”,例如需要使用
conio.h
“-lmsvcrt
”,但结果是悲观相同的。> ghci -lmsvcrt Examples.hs GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Examples.hs, interpreted ) Ok, modules loaded: Main. *Main> main ByteCodeLink: can't find label During interactive linking, GHCi couldn't find the following symbol: getch This may be due to you not asking GHCi to load extra object files, archives or DLLs needed by your current session. Restart GHCi, specifying the missing library using the -L/path/to/object/dir and -lmissinglibname flags, or simply by naming the relevant files on the GHCi command line. Alternatively, this link failure might indicate a bug in GHCi. If you suspect the latter, please send a bug report to: glasgow-haskell-bugs@haskell.org *Main>
GHCI可能会加载库,因为当我尝试加载错误的库时,ghci会输出错误。
我尝试了几个其他的东西,比如使用
ghci Examples.hs -fobject-code
,ghci -lmsvcrt Examples.hs -fobject-code
,甚至ghci Examples.hs "-luser32" "-lgdi32" "-lwinmm" "-ladvapi32" "-lshell32" "-lshfolder" "-lwsock32" "-luser32" "-lshell32" "-lmsvcrt" "-lmingw32" "-lmingwex" "-luser32" "-lmingw32" "-lmingwex" "-lm" "-lwsock32" "-lgdi32" "-lwinmm"
这在
ghc Examples.hs -v5
找到。可悲的是,没有什么比我的
main
更有用了,我找不到任何其他方法。PS有没有人知道如何在Windows中使用hSetBuffering(它是在8年前发布的ghc票#2189 。是不是已修复?)
First of all, I specify that I use Windows 10 64bit and Haskell Platform 8.0.1.
I try to use FFI of Haskell in Windows using following code.
import Control.Monad import Data.Char import Foreign.C getCh :: IO Char getCh = liftM (chr . fromEnum) c_getch foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt main :: IO () main = getCh >>= \x -> print x
After this, I can compile this well with ghc
> ghc Examples.hs [1 of 1] Compiling Main ( Examples.hs, Examples.o ) Linking Examples.exe ...
and it runs completely.
> Examples.exe '1'
(When I type 1 after running it)
However, the problem occurs with GHCI. When I load it to ghci, I got these messages.
> ghci Examples.hs GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Examples.hs, interpreted ) Ok, modules loaded: Main. *Main> main ByteCodeLink: can't find label During interactive linking, GHCi couldn't find the following symbol: getch This may be due to you not asking GHCi to load extra object files, archives or DLLs needed by your current session. Restart GHCi, specifying the missing library using the -L/path/to/object/dir and -lmissinglibname flags, or simply by naming the relevant files on the GHCi command line. Alternatively, this link failure might indicate a bug in GHCi. If you suspect the latter, please send a bug report to: glasgow-haskell-bugs@haskell.org *Main>
I try to load "missing library", such as "
-lmsvcrt
" which needs to useconio.h
, but result is pessimistically same.> ghci -lmsvcrt Examples.hs GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( Examples.hs, interpreted ) Ok, modules loaded: Main. *Main> main ByteCodeLink: can't find label During interactive linking, GHCi couldn't find the following symbol: getch This may be due to you not asking GHCi to load extra object files, archives or DLLs needed by your current session. Restart GHCi, specifying the missing library using the -L/path/to/object/dir and -lmissinglibname flags, or simply by naming the relevant files on the GHCi command line. Alternatively, this link failure might indicate a bug in GHCi. If you suspect the latter, please send a bug report to: glasgow-haskell-bugs@haskell.org *Main>
GHCI probably loads the library, since when I try to load a wrong library, ghci prints errors about that.
I try several other things, like using
ghci Examples.hs -fobject-code
,ghci -lmsvcrt Examples.hs -fobject-code
, and evenghci Examples.hs "-luser32" "-lgdi32" "-lwinmm" "-ladvapi32" "-lshell32" "-lshfolder" "-lwsock32" "-luser32" "-lshell32" "-lmsvcrt" "-lmingw32" "-lmingwex" "-luser32" "-lmingw32" "-lmingwex" "-lm" "-lwsock32" "-lgdi32" "-lwinmm"
Which was found in
ghc Examples.hs -v5
.Sadly, Nothing works for my
main
, and I can't find any otherway for this.P.S. Is there anyone knowing how to use hSetBuffering in Windows (It was posted at 8 years ago in ghc ticket #2189. Isn't it fixed?)
原文:https://stackoverflow.com/questions/38282624
最满意答案
在开发过程中删除“On Error GoTo”以更容易地看到有错误的行。
在处理所有子文件夹之前,您无需关注当前错误。
尝试这个:
Private Sub LoopFolders_Test() 'Application Variables Dim olApp As Outlook.Application Dim objNS As Outlook.Namespace Dim myolItems As Folder Dim Start As Date Dim EndTime As Date Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") 'Set myOlItems = objNS.GetDefaultFolder(olFolderInbox) Set myolItems = objNS.PickFolder If myolItems Is Nothing Then GoTo exitRoutine Start = Now Debug.Print "Start: " & Start Debug.Print "Startfolder Name: " & myolItems.Name 'Disable Screen Updating 'Application.ScreenUpdating = False LoopFolders myolItems.Folders ' Finalize Excel display here exitRoutine: Set olApp = Nothing Set objNS = Nothing Set myolItems = Nothing 'Enable Screen Updating 'Application.ScreenUpdating = True EndTime = Now Debug.Print "End : " & EndTime Debug.Print Format((EndTime - Start) * 86400, "#,##0.0") & " seconds" End Sub Private Sub LoopFolders(olFolders As Folders) Dim F As Folder For Each F In olFolders DoEvents Debug.Print "Subfolder Name: " & F.Name ' Code has not crashed ' Count mail here LoopFolders F.Folders Next End Sub
While in development remove "On Error GoTo" to more easily see the lines with errors.
You need not focus on the current errors until you can process all the subfolders.
Try this:
Private Sub LoopFolders_Test() 'Application Variables Dim olApp As Outlook.Application Dim objNS As Outlook.Namespace Dim myolItems As Folder Dim Start As Date Dim EndTime As Date Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") 'Set myOlItems = objNS.GetDefaultFolder(olFolderInbox) Set myolItems = objNS.PickFolder If myolItems Is Nothing Then GoTo exitRoutine Start = Now Debug.Print "Start: " & Start Debug.Print "Startfolder Name: " & myolItems.Name 'Disable Screen Updating 'Application.ScreenUpdating = False LoopFolders myolItems.Folders ' Finalize Excel display here exitRoutine: Set olApp = Nothing Set objNS = Nothing Set myolItems = Nothing 'Enable Screen Updating 'Application.ScreenUpdating = True EndTime = Now Debug.Print "End : " & EndTime Debug.Print Format((EndTime - Start) * 86400, "#,##0.0") & " seconds" End Sub Private Sub LoopFolders(olFolders As Folders) Dim F As Folder For Each F In olFolders DoEvents Debug.Print "Subfolder Name: " & F.Name ' Code has not crashed ' Count mail here LoopFolders F.Folders Next End Sub
相关问答
更多-
在开发过程中删除“On Error GoTo”以更容易地看到有错误的行。 在处理所有子文件夹之前,您无需关注当前错误。 尝试这个: Private Sub LoopFolders_Test() 'Application Variables Dim olApp As Outlook.Application Dim objNS As Outlook.Namespace Dim myolItems As Folder Dim Start As Date Dim ...
-
努力使用Excel VBA将文件附加到Outlook电子邮件(Struggling to attach files to Outlook e-mails using Excel VBA)[2023-07-31]
尝试完全限定您的工作簿并将字符串变量分配给您的范围 见例子 Option Explicit Sub SendEmail() Dim OutApp As Object Dim OutMail As Object Dim Sht As Object Dim RecipTo As String Dim RecipCC As String Dim Subject As String Dim Atmt As String With Applicatio ... -
虽然基本(并且失败了目的),但您可以使用VBA发送密钥来绕过安全提示。 在我的情况下,我需要按'n'表示'无',然后点击回车: Application.SendKeys "n" Debug.Print "key sent!" Application.SendKeys "{ENTER}" .Send Although rudimentary (and defeating the purpose), you could use VBA send-keys to circumvent the security ...
-
下面的代码使用此方法作为附件处理电子邮件 测试附件是否是电子邮件消息(如果文件名以msg结尾) 如果附件是消息,则将其保存为"C:\temp\KillMe.msg" 。 CreateItemFromTemplate用于将保存的文件作为新消息访问(msg2) 然后代码处理此临时消息以将attachmnets剥离到fsSaveFolder 如果附件不是消息,则根据您当前的代码提取它 请注意,因为我没有你的olFolder结构,Windoes版本, Outlook变量等我必须添加我自己的文件路径和Outlook文 ...
-
这条线 Set oWB = oXL.Workbooks.Save(saveFolder & "\" & objAtt.DisplayName) 需要引用先前存储的attachName字符串 Set oWB = oXL.Workbooks.Save(saveFolder & "\" & attachName) 因为那时objAtt Nothing 。 使用 MsgBox objAtt.DisplayName 就在保存之前,您可以检查它是否合适。 BTW注释掉隐藏Excel的行(Visible = Tru ...
-
使用VBA自动将HTML表格从Outlook导出到Excel(Automatically export HTML Table from Outlook to Excel w/ VBA)[2024-02-19]
改为将此行改为此 For i = 0 To olEleColl(0).Rows.Length - 1 (你拼写错误) I've found out that it wasn't working because the first table found didn't have any text in innerText, so I tested a macro that gets all the tables and it worked! Here's the code: Public Sub Salva ... -
在Excel中创建超链接以通过VBA打开特定电子邮件Outlook(Create Hyperlink in excel to open specific email Outlook by VBA)[2023-08-15]
一个简单的超链接将不允许在Outlook中打开邮件。 相反,您需要处理超链接单击(或按钮)并在Outlook中查找相应的条目。 Excel工作簿上显示的属性不允许唯一标识邮件项。 您可以使用EntryID值,但是当项目移动到Outlook中的另一个商店/文件夹时,它可以更改。 以下是MSDN所述的内容: MAPI商店提供程序在其商店中创建项目时分配唯一的ID字符串。 因此,在保存或发送Microsoft Outlook项目之前,不会为其设置EntryID属性。 当项目移动到另一个商店(例如,从收件箱到Mic ... -
Excel VBA:已发送的Outlook电子邮件不包含粘贴的范围(Excel VBA: Sent Outlook email does not include pasted Range)[2022-07-13]
但是,如果我一次运行整个Sub,没有断点,则发送的电子邮件在正文中没有粘贴的Excel范围。 这是什么原因,解决方案是什么? 原因很简单。 当您使用断点时,您将给Excel足够的时间进行复制粘贴。 因此,在使用其他应用程序时, SendKeys非常不可靠。 有很多方法可以解决您的问题。 一个是给复制粘贴足够的时间。 您可以通过使用DoEvents或强制Wait Time 。 例如 SendKeys "^({v})", True DoEvents 要么 SendKeys "^({v})", True Wai ... -
我不太确定我理解整件事情,但您可以尝试以下方法: Sub OpenMessage() Dim wb As Workbook, ws As Worksheet Dim mailOL As Outlook.Application, mailItems As Outlook.Items Dim mailFolder As Outlook.MAPIFolder, mail As Object Set wb = ActiveWorkbook Set ws = Sheets(" ...
-
我认为关键是这条线 ObjWB.ActiveWorkbook.Close 一定是 ObjWB.Close 。 请尝试此操作并评论您的结果。 I think the point is that the line ObjWB.ActiveWorkbook.Close must be ObjWB.Close . Please try this and comment your results.