|
Hi,
I'm trying to call a program in a .dll file that is built with C. The .dll program takes a pointer to a structure and then will return that structure with additional information filled in. The .dll program will also return a BOOL if the function was successful or not.
I have no problem calling the function, I'm having a problem building a structure that I can pass with a pointer.
From what I have been reading, I should be able to allocate a chunk of memory for the structure to hold, copy the existing data into the memory area and pass a pointer.
Attached below is my code that I am having a difficult time getting to compile. It starts with line number 265 with unsafe.
<br />
unsafe<br />
{<br />
<br />
IntPtr pCreditCardStruct = Marshal.AllocHGlobal(sizeof(CreditCardStruct));<br />
Marshal.StructureToPtr(CreditCardStruct, pCreditCardStruct, false);<br />
Marshal.Copy(CreditCardStruct, 0, pCreditCardStruct, sizeof(CreditCardStruct));<br />
}<br />
<br />
_ProcAuthorizationWeb(pCreditCardStruct);<br />
The structure looks like this:
<br />
[StructLayout (LayoutKind.Sequential)]<br />
public class CreditCardStruct<br />
{<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)] public string strTransType;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)] public string strMerchant;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] public string strInvoiceNumber;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)] public string strCardNumber;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4) ] public string strCVV2;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5) ] public string strExpDate;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 35)] public string strCardHolderName;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 25)] public string strStreetAddress;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] public string strZipCode;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9) ] public string strTransAmt;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7) ] public string strAuthCode;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)] public string strResponse;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bCardPresent;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bCustomerPresent;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bDeferred;<br />
}<br />
The error messages I'm getting are:
q:\mcp\authorization.aspx.cs(268,61): error CS0208: Cannot take the address or size of a variable of a managed type ('MCP.CreditCardStruct')
q:\mcp\authorization.aspx.cs(270,66): error CS0208: Cannot take the address or size of a variable of a managed type ('MCP.CreditCardStruct')
q:\mcp\authorization.aspx.cs(270,6): error CS1502: The best overloaded method match for 'System.Runtime.InteropServices.Marshal.Copy(int[], int, System.IntPtr, int)' has some invalid arguments
q:\mcp\authorization.aspx.cs(270,19): error CS1503: Argument '1': cannot convert from 'MCP.CreditCardStruct' to 'int[]'
q:\mcp\authorization.aspx.cs(273,27): error CS0103: The name 'pCreditCardStruct' does not exist in the class or namespace 'MCP.Authorization'
It appears that I can not use sizeof for the structure since its in "SAFE" code and I have the wrong format for the Marshal.Copy but from what I'm reading in the documentation it should be right.
Any ideas what I'm doing wrong and what is the best way to do this?
Thank you very much,
Glenn
|
|
|
|
|
Try passing the struct as a ref instead of an IntPtr
[DllImport("SomeDll.dll")]<br />
public static extern void _ProcAuthorizationWeb(ref pCreditCardStruct);<br />
<br />
CreditCardStruct pCreditCardStruct = new CreditCardStruct();<br />
_ProcAuthorizationWeb(ref pCreditCardStruct);<br />
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
i have a unmanaged dll in c++ that calls a
callback function in c# module
I want the c# code to fill an array for me
so the c++ code can use it
I can send an array but how can I do it by reference ?
osiliti
|
|
|
|
|
Hello there!
I am trying to create an export for DataGrids and Bitmaps into Excel.
To do this, I created an overloaded function with the ability of exporting into a specific worksheet.
Right at the moment, the function looks a little like this:
public void datagrid(GridTab gt_toexport, int sheetnr)<br />
{<br />
Excel.ApplicationClass excel = new ApplicationClass();<br />
Excel.Workbook excelWorkbook;<br />
<br />
<br />
if (File.Exists(target))<br />
{<br />
excelWorkbook = excel.Workbooks.Open(target,<br />
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",<br />
true, false, 0, true, false, false);<br />
}<br />
else<br />
{ <br />
excelWorkbook = excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);<br />
}<br />
<br />
Excel.Sheets excelSheets = excelWorkbook.Worksheets;<br />
<br />
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.Add(null, excelSheets.Count, 1, true);<br />
<br />
System.Data.DataTable table = gt_toexport.Table;<br />
<br />
<br />
excel.Save(target);<br />
}
All the things I marked with ***'s are things I am not sure about.. or dont actually work
Another thing is ... I dont know how to export a Bitmap object or an jpeg File into an excelsheet ... ;(
Would be great if you could help me out
Big TIA
|
|
|
|
|
Hi
Is there a way how to check if a workstation is locked and/or logged of?
|
|
|
|
|
Hi, im new to C# and i need some help printing HTML files programmatically.
Currenly i have created a windows application (C#), that scans a specified directory. For the files it should print. I am able to print the HTML files currently to any printer that is specified (without prompting at all). I use the Windows API SetDefaultPrinter to set the printer to which IE Must print.
The program scans the HTML files for this information.
Currenly i am also able to set the Headers,Footers,Margins by editing the registry.
But i need some help with setting the PaperSize,Copies (Or i could just loop),Orientation
Please let me know thanx.
|
|
|
|
|
I've been working for days on a project that creates a BAND OBJECT(BHO)in IE. This BAND has a button which when pressed finds a text box in the current HTML page, fills it in, then finds a button and clicks it to submit the page changes.
So far, I've found a terrific C# template that allows you to create a Band Object in IE. http://www.codeproject.com/csharp/dotnetbandobjects.asp
I've commented this code extensively and have done some Regional grouping to make the code clearer. Let me know if you'd like to see it.
Anyways, so I'm down to the part where I'm trying to access the HTML page. From my research, I've found that AxShDocVw, SHDocVw, mshtml references are needed to work with the browswer. Honestly, that's all the solid information I know. How do I take advantage of these references to access the browser and it's DOM?
I'm really pressed for time, so I'd appreciate your help...A LOT!
Thanks,
Dustin Lyday
~D
|
|
|
|
|
Hi,
am sure this question or one very much like it has been asked already by someone else but I can't find the thread so sorry for asking it again.
I have a screen with 1 listbox and 1 datagrid. The listbox is populated (via a stored procedure) with users.
I have another stored procedure which displays user info depending on whether 1 user is selected or all users are selected. What I need is to be able to select various users and then display the info.
How do I loop through the listbox?
Sorry again for re-asking old questions, please point me in the direction of the old thread if thats easier.
Really basic code sample below, I know the loop code has to sit in the 'else' section somehow.
private void btnRefresh_Click(object sender, System.EventArgs e)
{
if(chkSelectAll.Checked == true)
{
AllScannerCount();
}
else
{
SelectedScannerCount();
}
}
Thanks in advance
Scotty
|
|
|
|
|
I wrote a program that would change edi to xml.
Anyway the problem is to be able run the program from a network drive.
I keep getting Security Exception errors, regardless of how much I tried to play with the Security class (FileIOPermission or PermissionSet ....)
My question is:
Is there a way to request for the permission without using the .NET configuration or caspol.exe?
Thank you so much.. please help if you can
Elapid For The Win
|
|
|
|
|
No. The network is not a trusted source of executeable code. The application can't get permissions when the code is not trusted in the first place. You MUST configure CAS to allow the appropriate permissions for code running from a remote location.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I am writing an email client application in C#. Do you know if there is any .net Component that I can use to show the email message body..(since sometimes the message contains html)
|
|
|
|
|
Yes, use the Microsoft web browser control (put %system32%\shdocvw.dll in your Visual Studio toolbox, then drop it on your form). For advanced manipulation of the Microsoft web browser control, you may also need to add a reference to %program files%\microsoft.net\primary interop assemblies\Micrsoft.mshtml.dll
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lies of Our Fathers: A Must-Know About Lent
Judah Himango
|
|
|
|
|
Yes that is what i used but i thought maybe there is something else to handle every type of email message
|
|
|
|
|
Hello folks,
I would like to personalize my windows forms based on my security setting.I will define some user rights into my code and then I will try to apply these rules to my windows forms.
How can I start?What must I do?
Do you have any advices??
|
|
|
|
|
Hi All!
How to add controls dynamically inside a Richtextbox and set properties for the same......I know how to add controls to a Richtextbox dynamically but when i start typing in the Richtextbox the control overlaps whatever i type... how can i make it look like a normal text and the controls should be links..
I have a another question is it possible to identify the text which is getting deleted in a Textbox.... i mean the exact character which gets deleted when i press backspace.
Regards
Deepak.S
|
|
|
|
|
<br />
public enum Colors {Green, Red, Blue}<br />
How do I programatically know how many items are in that enum ? I need to create an array with the size of how many items are in that enum. For example when I have two items in the enum (Green, Blue), I have an array of size 2 (int[2]).
Regards,
Desmond
|
|
|
|
|
This will do it.
Enum.GetValues(typeof([type name of your enum])).Length;
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Very simple (if you know how, of course ):
Enum.GetValues(typeof(Colors)).Length GetValues() already returns an array, so perhaps you can use this one directly instead of creating one yourself.
Regards,
mav
|
|
|
|
|
I have a customized Print Preview dialog made of a Print Preview control.
When I increase zoom property, the document inside it gets enlarged and two scroll bars appear. But when I scroll down with Vertical scroll bar, it doesn't go till the bottom and bounce back upwords if I resize(enlarge) the Dialog it self. It doesn't show the bottom of the document in any case.
More over when the dialog is compressed and the document in side the preview control is not 100 % visible widthwise, the expected horizontal scroll doesn't appear.
What is the reason for such behavior?
Please guide
|
|
|
|
|
hi
i use a requer validator to control a textbox in a web page.
it works correctly on local but when i upload it to server the validator dosnt works.
whats the problem?
thanks
|
|
|
|
|
hi
Check if all the necessary file are there in the root directory of ur application in the IIS, the important file is aspnet_client.
cheers
chettu
|
|
|
|
|
hi
i checked and copy the aspnet_client folder to host root
but the problem still exist..
|
|
|
|
|
Hi
I had the same prob and the solution i gave solved the prob..... is that only ur app is not working properly or all the app running on the IIS.
|
|
|
|
|
Hi,
I want to insert a windows media player into my PDA program.
I find that the methods used in windows application can't be used in PDA.
Any default method can be used?
Or any other approach should be used?
Please help
Regards,
RockRock
|
|
|
|
|
hi friends.
i am facing a problem.
i want to display some text in a multilined texebox. actually its a text box, displaying some status. I want to show different color text for some perticular status. i tried using the color property of the textbox, but it changes the color of the entire box.
please help.
|
|
|
|