首先,我知道直接比较dllimport属性和getProcAddress函数是没有意义的.相反,我感兴趣的是比较两段代码,通过使用dllimport属性或使用getProcAddress函数导入函数,实现基本相同的事情 - 在dll中调用函数.具体来说,我正在编写一个C#应用程序,它在我编写的dll中使用了一些函数.起初我使用以下代码访问了我的dll函数:
class DllAccess
{
[DllImport("kernel32.dll", SetLastError = true)]
private extern IntPtr LoadLibrary(String DllName);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate Bool BarType(Byte arg); // return value indicates whether function call went well or not.
Bool Bar(Byte arg)
{
Bool ok = false;
IntPtr pDll= LoadLibrary("foo.dll");
if (pDll != IntPtr.Zero)
{
IntPtr pfunc = GetProcAddress(pDll, "bar");
if (pFunc != IntPtr.Zero)
{
BarType bar = (BarType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(BarType));
ok = bar(arg);
}
FreeLibrary(pDll);
}
return ok;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我后来需要获取lastError值,如果它已在dll调用期间设置,那么我将我的代码更改为:
class DllAccess
{
[DllImport("foo.dll", EntryPoint = …
Run Code Online (Sandbox Code Playgroud) 按照Real World Haskell第5章的练习,我最终得到了Prettify.hs,它除了其他东西外还输出了一个抽象类型的Doc和一个渲染函数compact,它是一个从Doc到String的函数.另一个文件PrettyJSON.hs导出renderJValue,最终给我一个Doc值.在我的主要部分中,我只导入renderJValue和compact,并使用一个输出作为另一个的输入.我很困惑为什么这样做.我认为导入抽象的Doc类型也是必要的.Haskell可以看到这两个函数在没有Doc导入的情况下组合在一起吗?
为了说明,这是我的Main.hs:
module Main where
import System.IO
import SimpleJSON (JValue(..))
import PrettyJSON (renderJValue)
import Prettify (compact)
main = do
let val = renderJValue $ JString "foo"
putStrLn $ compact val
getLine
Run Code Online (Sandbox Code Playgroud)
哪个输出
"foo"
Run Code Online (Sandbox Code Playgroud) 我在windows中做一些ruby脚本,包括打开和关闭浏览器.为此,我需要一些特殊的宝石来连接本机Windows系统调用.但是当我尝试的时候
> gem install sys-proctable
Run Code Online (Sandbox Code Playgroud)
它屈服了
ERROR: Could not find a valid gem ´sys-proctable´ (>= 0), here is why:
Found sys-proctable (0.9.0), but was for platforms x86-darwin-8
,x86-freebsd-7 ,x86-solaris-2.10 ,x86-linux ,x86-mswin32-60
Run Code Online (Sandbox Code Playgroud)
问题是我的gem安装没有x86-mswin32-60 rubygems平台
> gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
...
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
...
Run Code Online (Sandbox Code Playgroud)
似乎问题来自我使用mingw库编译的ruby版本.所以我的问题是:如何获得ruby版本,rubygems平台包含x86-mswin32-60?我找不到任何来自rubyinstaller.org的安装程序,这些安装程序不是mingw.
---编辑---
最后一部分有点草率.实际上,rubyinstaller.org具有为mswin32构建的传统一键式安装程序.但是这个安装对我来说还有一些问题,所以我想我会尝试下面的Luis解决方案.
编译Haskell程序时遇到问题,导入Text.Regex.Posix模块.我试图在一个小测试程序中隔离问题:
module Main () where
import Text.Regex.Posix ((=~))
main = return ()
Run Code Online (Sandbox Code Playgroud)
运行解释器工作正常:
/regex-test$ runghc Main.hs
/regex-test$
Run Code Online (Sandbox Code Playgroud)
但是,用ghc编译这个程序会产生:
/regex-test$ ghc -o tester Main.hs
Main.o: In function `rmS_info':
(.text+0xf3): undefined reference to `__stginit_regexzmposixzm0zi72zi0zi3_TextziRegexziPosix_'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
在此之后,解释器也停止工作:
/regex-test$ runghc Main.hs
<interactive>:1:32: Not in scope: `main'
/projects/regex-test$
Run Code Online (Sandbox Code Playgroud)
通过再次保存文件而不进行任何更改,我可以再次使用它.
有谁知道如何解决这个问题?
有关我系统的一些信息:
/regex-test$ uname -a
Linux Hello-Ubuntu 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:49:34 UTC 2009 i686 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
和
/regex-test$ ghc-pkg list
/usr/local/lib/ghc-6.10.3/./package.conf:
Cabal-1.6.0.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0, array-0.2.0.0,
base-3.0.3.1, base-4.1.0.0, bytestring-0.9.1.4, containers-0.2.0.1, …
Run Code Online (Sandbox Code Playgroud)