Find handle of MainForm in vb.net WPF [duplicate] - wpf

This question already has answers here:
Finding the handle to a WPF window
(5 answers)
Closed 3 years ago.
I am trying to find the handle of a VB.Net WPF application. I have tried various hWnd IntPtr commands with no luck
Me.Handle gives the error 'Handle' is not a parameter of MainWindow
Dim itnrp As IntPtr = Process.GetCurrentProcess().MainWindowHandle
gives the error:
error BC30657: 'ToPointer' has a return type that is not supported or parameter types that are not supported.
If I try putting it into a function to try and get the type that the above error appears to refer to like this...:
Public Function GetHandleOfWindow()
winHandle = Process.GetCurrentProcess().MainWindowHandle.GetType()
'Return winHandle
End Function
I get the same error BC30657 as previous
If I try:
Public winHandle As IntPtr
winHandle = New WindowInteropHelper(Me).Handle
I get the same error BC30657 as previous
Any help would be much appreciated!!

It would appear this is a bug within Visual Studio 2019
[https://developercommunity.visualstudio.com/content/problem/491378/vb-intptr-error-bc30657-topointer-has-a-return-typ.html]]

Related

system.nullreferenceexception 'object reference not set to an instance of an object.' vb.net [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 3 months ago.
i get this whenever i run this specific form and i do not know why this keep showing, pls help me how to solve this i do not know how to, i do not know what this means but as far as i know my other forms work perfectly fine
system.nullreferenceexception 'object reference not set to an instance of an object.' vb.net
This is the code:
public database as ADODB.Connection
public table as ADODB.RecordSet
Private Sub frmSales_Load(sender As Object, e As EventArgs) Handles MyBase.Load
database.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Windows10\Downloads\FinalsProject.accdb")
table.Open("select * from TB_Transactions", database, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
table.MoveFirst()
Call DisplayRecord()
Call DisabledControl()
End Sub
enter image description here
Your must init database, table before use:
database = New ADODB.Connection()
table = New ADODB.Recordset()

How do I replace MFC CDailog::OnTimer with ATL CAxDialogImpl method?

I had wrote a CMyDailog with MFC based on CDialog. And there is a OnTimer method override the CDialog one.
CMyDailog : public CDialog
{
afx_msg void OnTimer(UINT_PTR nIDEvent)
}
Now, we are migrating our MFC code to ATL. I have to make CMyDailog inherited from CAxDialogImpl<CMyDailog>.
CMyDailog : public CAxDialogImpl<CMyDailog>
{}
I didn't find an equivalent of CDialog::OnTimer in the ATL side. Do I have to use the Windows API ::SetTimer(GolbalTimerFunction) to achive that? In that case, I have to move my original member variable values into the globe scope -- I don't like that.
I find this maybe help:
https://www.codeproject.com/Messages/2870588/what-is-the-event-i-should-use.aspx
I found the equivalent one.
LRESULT OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
For more detail

VB Array IndexOf error (Noughts and Crosses Game)

Being new to programming and having it introduced to me through my course I've been doing tasks in and out of College in Visual Basic using Visual Studio to make games and other little applications. However in my most recent project i've experienced a problem in one of my arrays I have never come across before. The specific error im getting comes up with this when highlighted:
Data type(s) of the type parameter(s) in method 'Public Shared Overloads Function IndexOf(Of T)(array As T(), value As T) As Integer' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
I have all the arrays (18, for 9 different buttons each containing a question and an answer variant) running in form load as it was the only way I could get the arrays to work with a randomiser and show the question in the button. Then the array index is being found and created in the submit answer button. I'll give some snippets for further context below from various points where the array is being referenced :)
I created this to make the string global but I have an inkling this is wrong?
Public Class Form3
Public QBox1 As String
Public QBoxA1 As String
This is where the arrays are and how i've structured them
Public Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BOX 1 (TOP LEFT)
Dim QBox1() As String = {"√81", "4x6", "16/4", "21+18", "81-23"}
Dim QBoxA1() As Integer = {"9", "24", "4", "39", "58"}
And finally this is within the submit answer button where the error is
If QBoxA1.Contains(txt_AnswerAttempt.Text) Then
Dim question_index = Array.IndexOf(QBox1, btn_Q1.Text)
Dim answer_index = Array.IndexOf(QBoxA1, answerAttemptDisplay.Text)
If question_index = answer_index Then
MsgBox("Correct Answer!")
Else
MsgBox("Wrong Answer!")
End If
End If
Sorry for information overload, I wanted to be thorough right off the bat! Cheers for giving this a read if you made it to the end xD
Your declaration isn't right. Since you want an array, don't declare it as a single string. It should be:
Public QBox1() As String
then in the load event, don't re-declare it with a Dim statement. Just re-populate it:
QBox1 = {"√81", "4x6", "16/4", "21+18", "81-23"}

Xtrareport Databinding format string , "Object reference not set to an instance of an object" devexpress 12.2.7

I want to display thousand separator in Xtrareport, this code is work perfectly in DevXpress ver 14, but in ver 12.2.7, it's make an error:
An unhandled exception of type 'System.NullReferenceException' occurred in Kho3.exe
Additional information: Object reference not set to an instance of an object.
My code:
private void xxSL_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
xxSL.DataBindings["Text"].FormatString = "{0:N0}";
}
How to fix it?
DevExpress 12.2.x XRLable just don't have the DataBindings["Text"]. So I can't use it, for anyone get into this problem like me

strange problem with reflection and static method

Visual Studio 2008 - framework 3.5 - Visual Basic
Hi!
I have a problem with a static method invoked by reflection.
On the loading of my win-wpf I create a copy of "A4Library.dll" with the name "_temp.dll", in the same directory of the original.
Then, on a button-click event, I invoke a static method on the _temp.dll in this way:
Dim AssemblyFileName As String = Directory.GetCurrentDirectory() & "\_temp.dll"
Dim oAssembly As Assembly = Assembly.LoadFrom(AssemblyFileName)
Dim TypeName As String = "MyLibrary.MyService"
Dim t As Type = oAssembly.GetType(TypeName)
Dim mi As MethodInfo = t.GetMethod("MyMethod", BindingFlags.Static AndAlso BindingFlags.Public)
Dim bResponse As Boolean = mi.Invoke(Nothing, New Object() {MyPar1, MyPar2})
But this works well only if I the .exe file is not in the same directory of the .dll files, otherwise I obtain this error (translated):
InnerException {"Cast impossible of [A]MyType on [B]MyType. The type A is originated from ... in the context 'Default' in the position 'F:\MyPath\A4Library.dll'. The type B is originated from ... in the context 'LoadFrom' in the position 'F:\MyPath_temp.dll'."}
It's strange: it seems to be a conflict with the same method in the original .dll, but I can't undertend why it looks at the original and not at the copy. If the .exe file relative to the principal assembly is placed in another directory, all runs well.
I neet to have the .exe in the same folder of the .dll, how can I solve the problem?
Thank you!
Pileggi
Why create a copy of assembly before executing static method? If creating a copy is needed, load that assembly in another AppDomain and execute the method in there.

Resources