|
Hi,
I found a solution to the problem. I'm not sure if it's the best one, since I'm forced to use unsafe code, but it works. The code example I give below is a variation of the one in my previous post. To show that the mechanism works, I simply write the input buffer into the output buffer.
Thanks anyway to anyone who might have spent time looking for a solution.
C#
using System;
using System.Runtime.InteropServices;
using System.Globalization;
namespace CsharpManaged
{
class Program
{
public delegate void CallbackDelegate(
IntPtr INBuffer, UInt32 INBufferLength,
IntPtr OUTBuffer, UInt32 OUTBufferLength);
[DllImport("CppDLLUnmanaged.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void SetCallBackPointer(CallbackDelegate DelegatePassedToDLL);
[DllImport("CppDLLUnmanaged.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void InvokeCallBack();
static void Main(string[] args)
{
SetCallBackPointer(new CallbackDelegate(CallbackFunction));
InvokeCallBack();
Console.ReadLine();
}
private static void CallbackFunction(
IntPtr INBuffer, UInt32 INBufferLength,
IntPtr OUTBuffer, UInt32 OUTBufferLength)
{
Console.WriteLine("C#:");
unsafe
{
Byte* INptr = (Byte*)INBuffer.ToPointer();
Byte* OUTptr = (Byte*)OUTBuffer.ToPointer();
UInt32 length =
(INBufferLength < OUTBufferLength) ? INBufferLength : OUTBufferLength;
for (UInt32 i = 0; i < length; ++i)
{
Console.WriteLine(Convert.ToString(*INptr));
*OUTptr = *INptr;
++INptr;
++OUTptr;
}
}
Console.WriteLine();
}
}
}
C++ DLL
#include <iostream>
using namespace std;
typedef void __stdcall CALL_BACK_FUNCTION(char* INBuffer, unsigned long INBufferLength,
char* OUTBuffer, unsigned long OUTBufferLength);
CALL_BACK_FUNCTION *pFunction;
__declspec(dllexport) void __stdcall SetCallBackPointer(CALL_BACK_FUNCTION* FnAddress)
{
pFunction = FnAddress;
}
__declspec(dllexport) void __stdcall InvokeCallBack()
{
char* INBuffer, * OUTBuffer;
unsigned long INBufferLength, OUTBufferLength;
INBufferLength = 10;
OUTBufferLength = 15;
INBuffer = new char[INBufferLength];
OUTBuffer = new char[OUTBufferLength];
for(int i = 0; i < INBufferLength; ++i)
{
INBuffer[i] = i;
}
pFunction(INBuffer,INBufferLength,OUTBuffer,OUTBufferLength);
cout << "C++" << endl;
for(unsigned long i = 0; i < OUTBufferLength; ++i)
{
char digit;
itoa(OUTBuffer[i],&digit,10);
cout << digit << endl;
}
delete [] INBuffer;
delete [] OUTBuffer;
}
|
|
|
|
|
I want to search a file from server and want to copy it to the local disk.
how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server i can search.like y:\\serverfolde\\folder am tring to make an exe. different people will map to different drive. so i cant give like that.should give like @\\server\\serverfolde\\folder\\ but it is not working.
My code is
<br />
searchfolder="y:\\Template\\else";<br />
destination ="D:\\Princy\\My Documents\\project\\";<br />
string source=searchfolder+"\\"+"mod501_"+filetosearch+".3d";<br />
string target=destination+"mod501-"+filetosearch+".3d";<br />
string[] files = Directory.GetFiles(searchfolder, "mod501_"+filetosearch+".3d");<br />
if(files.Length==1)<br />
{<br />
foreach (string dir in files) <br />
{<br />
lblcnt.Text="Selected File: "+ dir;<br />
string[] search = Directory.GetFiles(destination,"mod501-"+filetosearch+".3d");<br />
if(search.Length>0)<br />
{<br />
lblcnt.Visible=true;<br />
lblcnt.Text="File already exist";<br />
}<br />
else<br />
{<br />
File.Copy(source,target);<br />
lblcnt.Visible=true;<br />
lblcnt.Text="File copied";<br />
}<br />
}<br />
what to give insted of
searchfolder="y:\\Template\\else";
If am using
searchfolder="@books\\template\\Template\\else";
am geting error:
System.IO.DirectoryNotFoundException:Could not find a part of the "@books\template\Template\els".
Otherwise its working perfectly.
|
|
|
|
|
Well for a start, you can't start a directory name with @. I assume you are wanting it to be something like @"\\server\directory\subdirectory". If you use the @, you put it before the quote and you double slash the server name.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
when i deployed my application,after some time am getting this error in server.(like after one day then am getting this error in my server and it is displaying "Service UnAvailable")
Error:
Application pool 'DefaultAppPool' is being automatically disabled due to a series of failures in the process(es) serving that applicat)ion pool.
any help appreciated.
Thanks
|
|
|
|
|
According to Microsoft, this may be caused by this[^].
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
i checked all the permissions for network it got full permissions.
A process serving application pool 'DefaultAppPool' exceeded time limits during shut down. The process id was '3796'.
this is wht the exact error msg wht am getting.
any help?
Thanks
|
|
|
|
|
hi all.
currently now i have a problem of saving the different data in the textbox into different files.
for example, when someone enters "hello" in textbox1 as "message.txt", and clicks send button, the streamwriter will save the file into a notepad as "message.txt" and the content will be "hello".
but is it possible to store that notepad permanently such that if the user clicks the send button another time with a different content like "goodbye", the streamwriter will save the file into a different notepad like "message2.txt" and the content will be "goodbye" ?
Hence, I will have 2 notepads in my debug folder, message.txt and message2.txt . is this possible?
help thanks!
|
|
|
|
|
For a start, you don't save the files to notepad. You save them as text files which can be opened with notepad.
Secondly, you need to write the file out using a FileStream.
FileStream fs = new FileStream("message.txt", FileMode.Create, FileAccess.Write, FileShare.None, 8192, false);
fs.Write(textValue, 0, textValue.Length);
fs.Close();
fs = null;
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks for replying. I've tried using FileStream and it works.
But how do i write the logic such that the name of the file changes whenever the FileStream is used?
|
|
|
|
|
troubled one wrote: for example, when someone enters "hello" in textbox1 as "message.txt", and clicks send button, the streamwriter will save the file into a notepad as "message.txt"
StreamWriter is not saving into notepad. It's saved as .txt file, and it's extension is mapped with notepad.exe on windows.
troubled one wrote: but is it possible to store that notepad permanently such that if the user clicks the send button another time with a different content like "goodbye", the streamwriter will save the file into a different notepad like "message2.txt" and the content will be "goodbye" ?
Use a filestream instead of StreamWriter. StreamWriter won't be able to create a file. But filestream can create file and write data to it. You need to keep a logic to avoid repeating the file name, if you are creating many files.
|
|
|
|
|
N a v a n e e t h wrote: StreamWriter won't be able to create a file.
Are you sure? StreamWriter creates a new file if it doesn't exist.
|
|
|
|
|
Giorgi Dalakishvili wrote: StreamWriter creates a new file if it doesn't exist.
YES.. I missed that point.
|
|
|
|
|
If you don't write large amounts of text and performance is not critical, you can also use the File class, which makes it trivially easy:
File.WriteAllText("message.txt", "Hello!");
If you'd like to append instead of overwriting, use File.AppendAllText .
|
|
|
|
|
Hai Everybody,
I want to generate the encrypted text.
I am encrypting using the SHA 256 algorithm.
Now i want to reduce this to 16 digit Hexadecimal format.
Can any one tell me how to reduce a text of any size to 16 digit Hexadecimal?
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Try with Cipher data class
SSK.
|
|
|
|
|
Thank you.
Can i get the string back.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
M. J. Jaya Chitra wrote: Now i want to reduce this to 16 digit Hexadecimal format.
Can any one tell me how to reduce a text of any size to 16 digit Hexadecimal?
What do you mean by "16 digit hexadecimal format"?
Do you mean a string with just 16 digits in it? 123456789ABCDEF0 has 16 hex digits.
Do you mean to reemphasise the fact that Hexadecimal is a base 16 number?
|
|
|
|
|
The input string will vary in size.
The output should be in 16 or 20 digit i.e a licence key.
Then can I get the string back by decoding.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
M. J. Jaya Chitra wrote: Then can I get the string back by decoding.
very unlikely. You'd need a lossless compression routine to do that, but a cryptographic hash should be essentially random and largely incompressible as a result.
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
M. J. Jaya Chitra wrote: The output should be in 16 or 20 digit i.e a licence key.
Not gonna happen. SHA256 encodes in blocks of 256 bits (or 32 bytes) so that is the smallest output you will get. If you want the string to be reversible then your output will be of comparable size to the input string (it will be rounded up to the next block boundary)
|
|
|
|
|
Hi Guys.
I need ur help Converting HTML to JPG Images format using C# using WEB Services
Can anyone know about XML Services and how will your write it
My Email Id nhsubash@gmail.com
Regrds
Subash
Subash
|
|
|
|
|
Hi,
have a look @ this http://www.guangmingsoft.net/htmlsnapshot/help.htm[^]
. may be you can get some idea.
but olny thing is coming to my mind right now is to render that html page and dump the screen bytes to am image.
that was just a thought , there could be some other way, you will get more good ideas from this forum.
Regards ,
Nishu
|
|
|
|
|
|
I have already got this but i need it using WEB Service
Subash
|
|
|
|
|
In that case first you will need to learn how to write web services
|
|
|
|