简体   繁体   English

如何使用ac dll从ac#项目读取文件?

[英]How can I read a file from a c# project using a c dll?

Been searching high and low for this one and can't seem to figure it out. 一直在寻找这一点,似乎无法弄清楚。

So I'm making a web application in visual studio using c# project. 因此,我正在使用c#项目在Visual Studio中制作一个Web应用程序。 There is another project in my solution, it's ac project that compiles to dll. 我的解决方案中还有另一个项目,它是一个编译为dll的ac项目。 I've gotten to the point where I can pass information between the two and it's working right. 我已经到了可以在两者之间传递信息的地步,并且工作正常。

In my application, the user uploads a file and it is saved to the file system in an "includes" folder. 在我的应用程序中,用户上载一个文件,并将其保存到“ includes”文件夹中的文件系统中。 The dll (compiled from c code I got from an sdk) is supposed to read in that file and decode it. dll(由我从sdk中获得的c代码编译而成)应该读取该文件并对其进行解码。 The dll project works fine when I compile it as an exe and send it a file path. 当我将其编译为exe并向其发送文件路径时,dll项目工作正常。

My question is, how can I get the DLL (now in the bin folder) to skip back a directory and grab this file? 我的问题是,如何获取DLL(现在位于bin文件夹中)以跳过目录并获取此文件? I've tried just hardcoding the file path into the c code but it doesn't work. 我已经尝试过仅将文件路径硬编码到C代码中,但是它不起作用。

FILE *fp;
bool isWorking = false
if(fp = fopen("../Include/testFile.fit", "r"))
    isWorking = true

I've also tried just writing to a text file from the DLL, hoping to find where it pops out and use that directory as a reference but the c code isn't creating and saving a file at all in that case. 我还尝试过仅从DLL写入文本文件,希望找到它弹出的位置并使用该目录作为参考,但在这种情况下c代码根本不会创建和保存文件。

The position of the DLL file in the file system is not important. DLL文件在文件系统中的位置并不重要。 The important part is where the resulting binary is run and what it sees as its current working directory. 重要的部分是生成的二进制文件在何处运行以及将其视为当前工作目录。

If your C# program uses the DLL, the code in the DLL will be run with the same current working directory as the C# program (unless you change it in the code in your DLL). 如果您的C#程序使用DL​​L,则DLL中的代码将在与C#程序相同的当前工作目录下运行(除非您在DLL中的代码中对其进行更改)。

So, you should try to load your file in the same way, with regards to path, as if you were to load it from your C# program. 因此,就路径而言,您应该尝试以相同的方式加载文件,就像从C#程序加载文件一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM